473,385 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Image URL?

I believe this must be a very sample question.

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

Jun 20 '06 #1
2 2706
MapPath is only good when you're trying to access the files on the server in
code, for example, when opening an Excel spreadsheet to edit, or to write an
image out. It won't do anything for the client.

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" <ro************@gmail.com> wrote in message
news:11**********************@f6g2000cwb.googlegro ups.com...
I believe this must be a very sample question.

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

Jun 20 '06 #2
Thanks for your reply.

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

Mark Fitzpatrick wrote:
MapPath is only good when you're trying to access the files on the server in
code, for example, when opening an Excel spreadsheet to edit, or to write an
image out. It won't do anything for the client.

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" <ro************@gmail.com> wrote in message
news:11**********************@f6g2000cwb.googlegro ups.com...
I believe this must be a very sample question.

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


Jun 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Pierre Tremblay | last post by:
Hi! I am trying to display an image in my html document. The document contains the following line: <td class="Input"><img...
3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
8
by: Jef Driesen | last post by:
I'm implementing some image processing algorithms in C++. I created a class called 'image' (see declaration below), that will take care of the memory allocations and some basic (mathematical)...
6
by: QuasiChameleon | last post by:
Hi, I'm trying to create a grayscale image class that reads and writes grayscale Targa format. This works well with smaller images, but corrupts larger images and creates a "Segmentation fault...
15
by: Anand Ganesh | last post by:
HI All, I have an Image. I want to clip a portion of it and copy to another image. How to do this? I know the bounding rectangle to clip. Any suggestions please. Thanks for your time and...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
6
by: comp.lang.php | last post by:
/** * Generate the random security image * * @access public * @param $willUseFilePath (default false) boolean to determine if you will be using a file path * @param mixed $filePath (optional)...
1
by: bharathv6 | last post by:
i need to do is modify the image in memory like resizing the image in memory etc ... with out saving it disk as i have to return back the image with out saving it disk PIL supports the use of...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.