Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have upload a image file using below code and the image is saving in Image folder and its data store in Image data type is <binary data=""> w.r.t ID and Name (i.e user name)

I want to retrieve that image and show on grid view, or you can say like when the use login his pic is displayed after login need help ..... need



C#
 protected void Button2_Click(object sender, EventArgs e)
    {
        try
        {

            TextBox2.Text = Label3.Text;
            string path = Server.MapPath("Images/");
            MyConn.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrated Security=True;User Instance=True";

            if (FileUpload1.HasFile)
            {
                string ext = Path.GetExtension(FileUpload1.FileName);
                if (ext == ".jpg" || ext == ".png")
                {
                    FileUpload1.SaveAs(path + FileUpload1.FileName);
                    string name = "~/images/" + FileUpload1.FileName;
                    string s = "insert into upload values ('" + TextBox1.Text + "', '" + TextBox2.Text + "', '" + name + "')";

                    MyComm = new SqlCommand(s, MyConn);

                    MyConn.Open();
                    MyComm.ExecuteNonQuery();
                    MyConn.Close();
                    Response.Write("Your file has been uploaded");

                }
                else
                {
                    Response.Write("You can only upload jpg or png file");
                }

            }
            else
            {
                Response.Write(" Please select a file");
            }


        }


        catch { }
    }
}
Posted
Updated 6-Nov-12 18:27pm
v2
Comments
ridoy 7-Nov-12 0:20am    
please retag it,it's should not be under codeproject tag..
MT_ 7-Nov-12 0:24am    
Agree with Ridoy. re-tag to get attention.

1 solution

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