Sett absolute path problem

P

Pumkin

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

Augustin Prasanna

'~/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
 
P

Pumkin

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?
 
A

Augustin Prasanna

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
 
P

Pumkin

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. :)
 
A

Augustin Prasanna

in this case, you can use ~\Request.ApplicationPath\Images\Picture.gif.. you
can set this from code behind.. Hope this helps.
 
P

Pumkin

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
 
R

Robert Haken [MVP]

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
 
P

Pumkin

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top