0

I have a web page that will display an image.

I created a folder within my website called 'photo' and uploaded that image to that folder using the following code: string path = Server.MapPath(@"~/Photo/"); FileUpload1.SaveAs(path+FileUpload1.FileName); I am using the following code but the image is not being displayed in the image control.

        string path = Server.MapPath(@"~/Photo/");
        Image1.ImageUrl = path + photoInfoObject.Photo;[photoInfoObject.Photo is a string of the name of the photo(eg: Penguins.jpg).]

still that image is not displaying.can anyone fix this?

Anu
  • 1
  • Is it displaying a broken image? – KhanS Sep 13 '10 at 07:25
  • No.Its not displaying anything. – Anu Sep 13 '10 at 08:47
  • Try this: http://stackoverflow.com/questions/275781/server-mappath-server-mappath-server-mappath-server-mappath – Sidharth Panwar Sep 13 '10 at 07:24
  • Thanks...But this is not what i want..image is not displaying in image control.is there any mistake in my coding? – Anu Sep 13 '10 at 07:36
  • Are you sure that the problem is not in the path variable? – Sidharth Panwar Sep 13 '10 at 07:54
  • Also, check if the image name and the path are not separated by a /. For e.g. is it xxx/photomyphoto.jpg instead of xx/photo/myphoto.jpg. – Sidharth Panwar Sep 13 '10 at 07:55
  • Another thing is while giving url your path can't be like C:\MySite\Photo\Myphoto.jpg because the web doesn't understand this. So try giving something like this (if you've to use local path) file:///C:/MySite/Photo/Myphoto.jpg. Although, I'd suggest you use http:// if possible by putting your image in the virtual directory folder. – Sidharth Panwar Sep 13 '10 at 07:59

1 Answers1

0

Your code looks ok so this is probably a broken link to your image, for example you may be rendering an absolute path to /Photo/Penguins.jpg, whereas if you're using the build in Visual Studio Web Server with a virtual directory, the absolute path would be /Your Site Name/Photo/Penguins.jpg. So check the generated HTML to find out the path, and maybe use the "Net" panel inside the Firebug plugin for Firefox to easily see any 404 errors as the page loads.

TimS
  • 5,460
  • 6
  • 30
  • 54