Click here to Skip to main content
15,923,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need a way of making an image name validation so that a message is sent every time a user sends/posts an image with a name that already exists.

The problem is people posts the same images all over and again because the is nothing that stops them from doing so. Now i need to find a way of putting a stop to that so that every time a user sends the same image a Message Box shows up and say "This image already exist" so that the user may know that now i need to change and post another one. Please help!

Here's my code:

C#
public class ImageHandler : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {

        {
            System.Data.SqlClient.SqlDataReader rdr = null;
            System.Data.SqlClient.SqlConnection conn = null;
            System.Data.SqlClient.SqlCommand selcmd = null;
            try
            {
                //string path =""
                conn = new System.Data.SqlClient.SqlConnection
              (System.Configuration.ConfigurationManager.ConnectionStrings
              ["LiveAdsConnectionString"].ConnectionString);
                selcmd = new System.Data.SqlClient.SqlCommand
             ("select Image from Adverts where AdvertsID=" +
              context.Request.QueryString["id"], conn);
                conn.Open();
                rdr = selcmd.ExecuteReader();
                while (rdr.Read())
                {
                    context.Response.ContentType = "image/jpg";
                    context.Response.ContentType = "image/png";
                    context.Response.WriteFile("/Images/" + rdr["Image"].ToString());
                }
                if (rdr != null)
                    rdr.Close();
            }
            finally
            {
                if (conn != null)
                    conn.Close();
            }

        }
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
Posted
Updated 10-Sep-15 0:12am
v3
Comments
George Jonsson 10-Sep-15 5:18am    
So what is the problem?

1 solution

as you already knows and doing, you need to put query to find the file name which is currently being uploaded by user and if match happens , prompt user.

Do you have any other scenario then explain to get more inputs on this.

Cheers
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900