Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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:

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 29-Apr-13 12:49pm
Edited 29-Apr-13 18:14pm
_Amy51.5K
v2
Comments
ThePhantomUpvoter at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
Comments
wajid khaksar at 30-Apr-13 6:48am
   
Lot of thanks Sir, i found solution here.
rk_prabakar at 30-Apr-13 8:31am
   
Welcome pal...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 130
4 DamithSL 105
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100