I have a image dir under myWebsite (myWebSite is the root dir of my web
appl)
I have an ascx file under myWebsite/userControls
in the c# of ascx file, I load a image file using MapPath.
imgSort.ImageUrl = Server.MapPath("Images/sort_asc.gif");
If I check the source from IE
I found that the imgSort's image is c:\myWebsite\sort_asc.gif
It points to my client local c driver and the img does not show up.
Of course if I access myWebsite from server, I got the correct image,
'cause that is the C driver on server.
I tried to use relative path, but got no luck.
How should I point to the image url?
Thanks a lot
-Rockdale
You can take the application path, and add the path to the file with it like
so:
imgSort.ImageUrl = Request.ApplicationPath + "/Images/sort_asc.gif";
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
"rockdale" <rockdal...@gmail.com> wrote in message
news:1150767611.7...@f6g2000cwb.googlegroups.com...
It is works, partially, I would say.
On my development machine, I have this dir structure
c:\Inetpub\wwwroot\MYWEBSITE
On my production machine, I did not put MYWEBSITE under Inetput. I put
it under c:
c:\MYWEBSITE
So my user control's dir is
Dev Server c:\Inetpub\wwwroot\MYWEBSITE\userControls and
Production Server c:\MYWEBSITE\userControls
my image's dir is
Dev Server c:\Inetpub\wwwroot\MYWEBSITE\Images
Production Server c:\MYWEBSITE\Images
Trying to understand the dir completely, I tried the following cases. I
access MYWEBSITE from developement server itself. from a client other
than production server. and from production server itself. And I got
the following result
my understanding is, absolute dir does not work if the production
website is under a different dir than it is on dev server. If it works
on dev server, then it won't work on production server, vise versa.
finally, I go for relative path, I am not sure is it the best solution,
but it works on both dev server and production server.
I really hoped that Request.ApplicationPath + "/Images/sort_asc.gif";
is smart enough to know the application path, but it is not.
Maybe I am missing something?
The folowing shows the ImageUrl used in code behind, the HTML url that
generates and if it works.
imgSort.ImageUrl = "Images/sort_desc.gif"
Dev Server
http://localhost/MYWEBSITE/Controls/Images/sort_desc.gif doesn't work
Client - Production Server
http://WEB_SERVER_NAME/Images/sort_asc.gif Works
Production Server
http://WEB_SERVER_NAME/Images/sort_asc.gif Works
imgSort.ImageUrl = Request.ApplicationPath + "Images/sort_desc.gif";
Dev Server
http://localhost/MYWEBSITEImages/sort_asc.gif doesn't work
Client- Production Server
http://WEB_SERVER_NAME/Images/sort_asc.gif works
Production Server
http://WEB_SERVER_NAME/Images/sort_asc.gif works
imgSort.ImageUrl = Request.ApplicationPath + "/Images/sort_asc.gif";
Dev Server
http://localhost/MYWEBSITE/Images/sort_desc.gif works
Client-Productiion Server
http://images/sort_desc.gif doesn't work
Production Server
http://images/sort_asc.gif doesn't work
imgSort.ImageUrl = "../Images/sort_asc.gif";
DEV SERVER
http://localhost/MYWEBSITE/Images/sort_asc.gif WORKS
Production Server
http://WEB_SERVER_NAME/Images/sort_asc.gif WORKS
Client-Production Server
http://WEB_SERVER_NAME/Images/sort_asc.gif WORKS