Click here to Skip to main content
15,898,538 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
How to display image in in image box through asp.net 2.0
i have written code for it...and i use fileuploadImage control.

C#
if (fileuploadImage.HasFile)
            {
          
            int length = fileuploadImage.PostedFile.ContentLength;
           
            byte[] imgbyte = new byte[length];
           
            HttpPostedFile img = fileuploadImage.PostedFile;
          
            img.InputStream.Read(imgbyte, 0, length);
          
            Image1.ImageUrl = Server.MapPath(fileuploadImage.FileName);


but the image not displaying. please help me...
thanks.
Posted

You will need to save the uploaded image to a file and then set the ImageUrl to the path that you save the image to.
 
Share this answer
 
C#
if (fileuploadImage.HasFile)
{
     fileuploadImage.SaveAs(Server.MapPath("~/") + fileuploadImage.FileName);

     Image1.ImageUrl = "~/" + fileuploadImage.FileName;
}
 
Share this answer
 
Please take a look at this Code Project Q/A.To display binary formatted image from database[^]
 
Share this answer
 
you need to have http handler to laod the image in image control...
 
Share this answer
 
Solution 3 is much better... and I Have tried my self..... wonderful practice.... But i want to show the images from DATABASE.... how can i retreive the image from database and it will be shown in imagebox.... kindly let me know its urgent....


Thanx regards
Sajid Asghar
 
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