473,387 Members | 1,721 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,387 software developers and data experts.

Sett absolute path problem

Hello guys,

I have a small problem with setting the absolute path of an image.
Here is the scenario:

I need to put the image in a text concat something like this:

<asp:Label id = "lbl" runat = "server" text = "<img id = 'img' src =
'Images/picture.gif' /text " />

If I put a relative path everything is perfect, but if I try an
absolute path it is not working.
I have already tried:

<asp:Label id = "lbl" runat = "server" text = "<img id = 'img' src =
'/Images/picture.gif' /text " />
<asp:Label id = "lbl" runat = "server" text = "<img id = 'img' src =
'~/Images/picture.gif' /text
runat = 'server' " />

It seems like an easy thing to do but I cannot make it work.

Thanks for the help...

Oct 12 '06 #1
9 1514
'~/Images/picture.gif' will look for picture.gif in
'<rootweb>\Images\picture.gif'

In case, if you are using a virtual directory set up, your image will
actually be in '<rootweb>\<virtual directory>\images\picture.gif'.

Hope this helps.

Regards,
Augustin

"Pumkin" <Po********@gmail.comwrote in message
news:11*********************@c28g2000cwb.googlegro ups.com...
Hello guys,

I have a small problem with setting the absolute path of an image.
Here is the scenario:

I need to put the image in a text concat something like this:

<asp:Label id = "lbl" runat = "server" text = "<img id = 'img' src =
'Images/picture.gif' /text " />

If I put a relative path everything is perfect, but if I try an
absolute path it is not working.
I have already tried:

<asp:Label id = "lbl" runat = "server" text = "<img id = 'img' src =
'/Images/picture.gif' /text " />
<asp:Label id = "lbl" runat = "server" text = "<img id = 'img' src =
'~/Images/picture.gif' /text
runat = 'server' " />

It seems like an easy thing to do but I cannot make it work.

Thanks for the help...

Oct 12 '06 #2
Thank you for your interest and for the reply.

The problem is that if I put :

Text="<img id='img1' runat = 'server' src = '~/Images/picture.gif' />
Text"

and if I look in View Source in IE I can see that it doesn't put any
path at all:

Text="&lt;img id = 'img1' src='~/Images/picture.gif' alt='' runat =
'server' /&gt; Text"

And if I put the realtive path it understands the path corectly.

Any ideas?

Oct 12 '06 #3

Lets say that my web site is on localhost and has the virtual directory
MyWebSite.

Of course if I set the path src '
"http://localhost/MyWebSite/Images/picture.gif" it is working.
But I was wondering if there isn't a better way to do this.

Regards,

Oct 12 '06 #4
it will not put any path if you use '~\Images'. It knows where to look for..

Can you try putting in '..\Images\picture.gif' and tell me if this works?

Regards,
Augustin

"Pumkin" <Po********@gmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
Thank you for your interest and for the reply.

The problem is that if I put :

Text="<img id='img1' runat = 'server' src = '~/Images/picture.gif' />
Text"

and if I look in View Source in IE I can see that it doesn't put any
path at all:

Text="&lt;img id = 'img1' src='~/Images/picture.gif' alt='' runat =
'server' /&gt; Text"

And if I put the realtive path it understands the path corectly.

Any ideas?

Oct 12 '06 #5

If I put '..\Images\picture.gif' it works.

But the img is in a user control and it is used in 2 pages.
And depending on the page that it is used I need to have as path
'..\Images\picture.gif' and '..\..\Images\picture.gif'. So I cannot
really used a relative path. :)

Oct 12 '06 #6
in this case, you can use ~\Request.ApplicationPath\Images\Picture.gif.. you
can set this from code behind.. Hope this helps.
"Pumkin" <Po********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
>
If I put '..\Images\picture.gif' it works.

But the img is in a user control and it is used in 2 pages.
And depending on the page that it is used I need to have as path
'..\Images\picture.gif' and '..\..\Images\picture.gif'. So I cannot
really used a relative path. :)

Oct 12 '06 #7

Thank you very much for the solution offered.
But I would rather not put the path from code-behind if possible (it is
really difficult to do this in my situation).
Is there other solution (from HTML) ??
Sorry for so many questions here...

Regards,
Pumkin

Oct 12 '06 #8
Thank you very much for the solution offered.
But I would rather not put the path from code-behind if possible (it is
really difficult to do this in my situation).
Is there other solution (from HTML) ??
Sorry for so many questions here...
If you realy need this weird construction, you can use data-binding:

<asp:Label ID="MyLabel" Text="<%# "<img src='" +
ResolveUrl("~/images/myImage.gif") + "' alt='xxx' />" %>" runat="server" />

....and don't forget to call MyLabel.DataBind() or Page.DataBind() form code.
Robert Haken [MVP ASP/ASP.NET]
HAVIT, s.r.o., www.havit.cz
http://knowledge-base.havit.cz
Oct 12 '06 #9

It seems it is hopeless.. In the situation that I am having I cannot
use server directives to set the path.
To detail a little bit more the control in which I want to put the
image is not a label,
but the atlas control expandable panel and it doesn't allow me to put
server code.

Thanks for the help everybody anyway.

Oct 12 '06 #10

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

Similar topics

4
by: dchaffin | last post by:
I'm having a problem using file_exists with an absolute path and I can not figure out why. I tried the exact example that is on www.php.net ... <?php $filename = '/path/to/foo.txt'; if...
3
by: rajuvk | last post by:
I am setting up a website with a number of folders like: / (the document root) /user /admin/ /content in the /user folder there is a flie "userlogged.php", which I want to include in every...
9
by: Stuart | last post by:
Hi All, I got a challenge to make the same APS/Script/Html run on different web roots. I can not use relative pathing in a lot of cases. We use lots of included files so depending on where that...
15
by: Nick K. | last post by:
I recently began maintenance work on a production web server that is located in the root directory of a web server. I moved this into a sub web on my local web server in order to do work on it. I...
1
by: William Starr Moake | last post by:
Another problem with absolute paths in the WYSIWYG editor I'm putting together. The function to toggle between WYSIWYG and HTML modes works except for one glitch. If you use a relative path for...
3
by: JeffDotNet | last post by:
I wrote a small data processing application that writes a summary of several hundred files. I use drag and drop on a panel (Panel1) to grab the absolute path to each of these files. Then I begin...
19
by: Jerry M. Gartner | last post by:
Greetings: What is the best way to resolve paths within a document regardless of what path it is opened under? For example: I have x.php and it contains <img src="images...">, (amongst other...
6
by: Jon Slaughter | last post by:
do I have to prefix every absolute path with document root to get it to work? For some reason I thought that prefixing a path with '/' or './' with make it absolute w.r.t to document root but I...
22
by: SETT Programming Contest | last post by:
The SETT Programming Contest: The fastest set<Timplementation Write the fastest set<Timplementation using only standard C++/C. Ideally it should have the same interface like std::set. At least...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.