Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Sett absolute path problem

Reply
Thread Tools

Sett absolute path problem

 
 
Pumkin
Guest
Posts: n/a
 
      10-12-2006
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...

 
Reply With Quote
 
 
 
 
Augustin Prasanna
Guest
Posts: n/a
 
      10-12-2006
'~/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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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...
>



 
Reply With Quote
 
 
 
 
Pumkin
Guest
Posts: n/a
 
      10-12-2006
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?

 
Reply With Quote
 
Pumkin
Guest
Posts: n/a
 
      10-12-2006

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,

 
Reply With Quote
 
Augustin Prasanna
Guest
Posts: n/a
 
      10-12-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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?
>



 
Reply With Quote
 
Pumkin
Guest
Posts: n/a
 
      10-12-2006

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.

 
Reply With Quote
 
Augustin Prasanna
Guest
Posts: n/a
 
      10-12-2006
in this case, you can use ~\Request.ApplicationPath\Images\Picture.gif.. you
can set this from code behind.. Hope this helps.


"Pumkin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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.
>



 
Reply With Quote
 
Pumkin
Guest
Posts: n/a
 
      10-12-2006

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

 
Reply With Quote
 
Robert Haken [MVP]
Guest
Posts: n/a
 
      10-12-2006
> 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


 
Reply With Quote
 
Pumkin
Guest
Posts: n/a
 
      10-12-2006

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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How does one get an absolute absolute file path? James Byrne Ruby 3 09-14-2010 06:02 PM
The SETT Programming Contest: The fastest set<T> implementation SETT Programming Contest C++ 18 06-05-2008 04:39 PM
Absolute path in Manifest Class-Path header? bo_kid@yahoo.com Java 10 05-30-2005 01:43 PM
absolute path versus relative path in JSP Matt Java 3 07-08-2004 08:31 PM
Make a relative url path from an absolute path to another one Thomas Guettler Python 3 10-27-2003 04:41 PM



Advertisments