Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi every one;
i am beginners in asp.net.
here i have a problem is that:
I have two webfrom in one form i upload images in database. That is uploaded successfully.
in 2nd form i have one image button and one image box. I want that when user click image button then new uploaded image is displayed in image box.
in other words i want to know how to retrieve images from database and display in image box.
please give me some hints as soon as possible;
thanks in advance.

here is my image upload code:

C#
SqlConnection con = new SqlConnection(@"connection string");
        SqlCommand com;
        photo phobj=new photo();
        protected void btnsubmit_Click1(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                String filename = FileUpload1.PostedFile.FileName;
                String FileExtension = Path.GetExtension(filename).ToLower();
                String[] ExtesionAllowed = { ".png", ".gif" };
                if (FileExtension.Contains(Path.GetExtension(filename).ToLower()))
                {
                    try
                    {
                        String FileSavePath = Server.MapPath("~/Photos/");
                        FileUpload1.PostedFile.SaveAs(FileSavePath + FileUpload1.PostedFile.FileName);

                    }
                    catch (Exception)
                    {
                        lblmsg.Text = "unable to upload.";
                    }
                }
                else
                {
                    lblmsg.Text = "File Extension " + Path.GetExtension(filename).ToLower() + " is not allowed";
                }

                phobj.url = Path.GetFileName(filename);
                phobj.alpha = drp_name.SelectedItem.Text.ToString();
                phobj.message = txtname.Text;
                con.Open();
                string query = "Insert Into Images(url,name,message)Values('" + phobj.url + "','" + phobj.alpha + "','" + phobj.message + "')";
                com = new SqlCommand(query, con);
                if (com.ExecuteNonQuery() > 0)
                {
                    lblmsg.Text = "Images Submited";
                }
            }
                else
                {
                    lblmsg.Text = "Operation Failed...please try again...";
                }
                con.Close();
            
        }
Posted
Updated 29-Apr-13 17:14pm
v2
Comments
[no name] 29-Apr-13 17:54pm    
As just answered by Sergey, http://www.codeproject.com/Answers/585412/Howplustoplusuploadplusaplusimageplusintoplusdatab#answer1, you just need to do a search and find the answer yourself.

Hi Wajid,

I worked on the same task earlier and I am pleased you asked this question here....
You can refer this Link[^] for sample code.

I hope this would help you a bit.
 
Share this answer
 
Comments
Wajid Khaksar 30-Apr-13 6:48am    
Lot of thanks Sir, i found solution here.
♥…ЯҠ…♥ 30-Apr-13 8:31am    
Welcome pal...
hi bro .. can you tell me please that is this code also work for mobile image upload I mean i want to saved image on mobile and than retrieved it .. please help me if you can .. thanks.
 
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