Sett absolute path problem

Discussion in 'ASP .Net' started by Pumkin, Oct 12, 2006.

  1. Pumkin

    Pumkin Guest

    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...
    Pumkin, Oct 12, 2006
    #1
    1. Advertising

  2. '~/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" <> wrote in message
    news:...
    > 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...
    >
    Augustin Prasanna, Oct 12, 2006
    #2
    1. Advertising

  3. Pumkin

    Pumkin Guest

    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?
    Pumkin, Oct 12, 2006
    #3
  4. Pumkin

    Pumkin Guest

    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,
    Pumkin, Oct 12, 2006
    #4
  5. 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" <> wrote in message
    news:...
    > 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?
    >
    Augustin Prasanna, Oct 12, 2006
    #5
  6. Pumkin

    Pumkin Guest

    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. :)
    Pumkin, Oct 12, 2006
    #6
  7. in this case, you can use ~\Request.ApplicationPath\Images\Picture.gif.. you
    can set this from code behind.. Hope this helps.


    "Pumkin" <> wrote in message
    news:...
    >
    > 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. :)
    >
    Augustin Prasanna, Oct 12, 2006
    #7
  8. Pumkin

    Pumkin Guest

    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
    Pumkin, Oct 12, 2006
    #8
  9. > 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
    Robert Haken [MVP], Oct 12, 2006
    #9
  10. Pumkin

    Pumkin Guest

    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.
    Pumkin, Oct 12, 2006
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    3
    Views:
    19,505
    Sudsy
    Jul 8, 2004
  2. Replies:
    10
    Views:
    3,481
  3. Thomas Guettler
    Replies:
    3
    Views:
    740
    Andrei
    Oct 27, 2003
  4. SETT Programming Contest
    Replies:
    18
    Views:
    630
    Ben Pfaff
    Jun 5, 2008
  5. James Byrne
    Replies:
    3
    Views:
    542
    James Byrne
    Sep 14, 2010
Loading...

Share This Page