Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to display an image in my image control from a folder that is not included in my project. how can i do that? I am giving the code i am using but it is not working...Pleas guide what is wrong with that code..Remember that folder(Uploads) is not included in my project file and I don't want to include that folder as well...

string path = Server.MapPath("~/Uploads/Chrysanthemum_3.jpeg");
imgPicture.ImageUrl = path;
Posted

1 solution

if its a server side control. you need to set the virtual path.

Server.MapPath(".") returns the current physical directory of the file (e.g. aspx) being executed
Server.MapPath("..") returns the parent directory
Server.MapPath("~") returns the physical path to the root of the application
Server.MapPath("/") returns the physical path to the root of the domain name (is not necessarily the same as the root of the application)

use
string path = Server.MapPath("~") + "/Uploads/Chrysanthemum_3.jpeg"; <br />
imgPicture.ImageUrl = path;
 
Share this answer
 
Comments
touseef4pk 6-Jun-11 9:47am    
it is not working sir..it gives me.. D:\Touseef\Projects\HomeAlone\HomeAlone.Web\/Uploads/Chrysanthemum_3.jpeg..which is invalid path(having "\/") and image could not be found.
Ciumac Sergiu 6-Jun-11 10:02am    
Try deleting the slash, and place backslash:
string path = Server.MapPath("~") + "Uploads\\Chrysanthemum_3.jpeg";

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