+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How can I use tilde in relative path in generic content html?

How can I use tilde in relative path in generic content html?

14 posts, 0 answered
  1. Eugene
    Eugene avatar
    3 posts
    Registered:
    19 Jul 2008
    29 Jul 2008
    Link to this post
    Hello,

    Could you please help me with the following issue. I have a set of pages with different level in site hierarchy. But I need to show site logo on every page. Problem is that relative path to logo is different from each page perspective. And I cannot use neither absolute path, not web server root relative path. I tried to use asp.net virtual directory relative path using ~ (tilde) but it didn't worked in generic content html. More detailed description of the problem below:

    http://localhost/MySite

    MySite
    - Images
    -- logo.gif
    - Homepage.aspx
    - Publications
    --Article1.aspx

    I want to show logo.gif in text of Article1.aspx and in text of Homepage.aspx
    When I use absolute path, e.g. <img src="http://localhost/MySite/Images/logo.gif"/> it works ok. But I want to use relative path, so that after site deployment to production environment there is no need to fix all the urls, which would be just impossible. I tried to use the following path:
    <img src="~/Images/logo.gif" /> but it didn't work, logo wasn't loaded, the path to logo image in browser was http://localhost/MySite/~/Images/logo.gif

    This solution is not feasible either: <img src="/MySite/Images/logo.gif" />, as this would also require to change all urls at production, when site will be refered by domain name.

    Could you please advice me, what is the best way to specify image and page urls in sitefinity in order to ease deployment?
  2. Vassil Daskalov
    Vassil Daskalov avatar
    261 posts
    Registered:
    18 May 2013
    30 Jul 2008
    Link to this post
    Hello Eugene,

    The best way to set your image path in a Generic Content item is to use an absolute path relative only to the application name (i.e. to set the src attribute to: /YourAppName/Images/logo.gif). That would mean that you need to update the path once you upload your project to the production server.

    That is why we would recommend that you use the microsoft Image control which is available in the toolbox on the right, and not the Generic content control. What you will need to do is set the ImageUrl property to: ~/Images/logo.gif, and the image would be the same in both environments.

    I hope this solution will work for you.
    Please, let me know if you need more assistance.

    All the best,
    Vassil
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    30 Jul 2008
    Link to this post
    i've wrestled with this problem long before sitefinity... I've never been able to find a good solution. thankfully at work we have vista which allows multiple websites, so I can use the root /images without the application folder...

    one thing you might consider is IIS Admin http://www.jetstat.com/iisadmin/ which lets you create multiple websites in xp. you can only run one at a time, but this will allow you to develop from the "root" of the site instead of a "virtual directory" beneath the root, and that way you won't have to update anything when you move to production!
  4. Eugene
    Eugene avatar
    3 posts
    Registered:
    19 Jul 2008
    30 Jul 2008
    Link to this post
    Yeah, the problem with tilde (~) is that it works only in asp.net server controls. Vassil gave useful advice about using image control, but it brings another problem:
        I use logo in generic content and then share this content, so all 3 templates use it. But I believe there is no possibility to share control in sitefinity (please correct me if I'm wrong, that would be wonderful opportunity).

    I'm going to look at IIS Admin, thanks SelArom !
  5. Pepi
    Pepi avatar
    981 posts
    Registered:
    16 Sep 2016
    01 Aug 2008
    Link to this post
    Hi Eugene,

    We confirm that you can not shared controls in Sitefinity.
    What you can do is declare the Image control directly in the master pages that should display the picture like this:

    .master
        <form id="form1" runat="server"
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 
            <div id="wrapper"
            <div id="Header"
                <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/logo.gif" /> 

    Hope this helps.

    Kind regards,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. LizzyM
    LizzyM avatar
    14 posts
    Registered:
    05 Oct 2009
    09 Oct 2009
    Link to this post
    Hello Pepi and Vassil!

    Ok, can we have the definitive solution to paths please? As I am getting confused by the various solutions.

    Eugene asked the same question I am trying to find an answer to.

    I see how the <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/logo.gif" />
    works withing masterpages, and I thank you for clearing that up. It worked great in that instance.

    However, if I have some shared content which contains images (for example a button that says 'download adobe acrobat' with an image of the acrobat logo) which I would like to appear in the right column on a lot of the pages.

    The problem is, that some of the pages are in lower levels of hierarchy (nested pages) and when I select the shared content to insert in that page, suddenly the page will not display the image. (see attached source). That is because it changes the ~/ to " src="/WebSite2/App_Themes/Emerald-Blue/images/icons/get-adobe-reader.gif" and if I don't add the tilde, it just doesn't find the folder because it is looking in the wrong place.

    So what do I do in this situation? What is the best solution?
    Can I add something to the web.config file which will solve this problem?

    thanks in advance for any help. (ps. As I am not a developer, please try and be easy on me!)

    Liz
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    09 Oct 2009
    Link to this post
    Hello LizzyM,

    The image should not be broken because we add an additional attribute sfref which looks like sfref="~/App_Themes/Orange with left sidebar/Images/prev.gif". You can also upload all items to Images and Documents library. From 3.6 we use dynamic link parser that gets items or pages by the provider name and ID, not by url.

    I hope this helps.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. LizzyM
    LizzyM avatar
    14 posts
    Registered:
    05 Oct 2009
    09 Oct 2009
    Link to this post
    Ok Thanks Ivan, I will upload the files to the library first.

    many thanks,

    liz
  9. Bart Welch
    Bart Welch avatar
    64 posts
    Registered:
    10 Jul 2009
    19 Nov 2009
    Link to this post
    When we link to another page within Sitefinity in our testing environment, it adds the full path which includes the localhost server name.  How can we make these links to other internal pages relative so when we move the site to our production servers they will continue to work on any domain or subdomain we place it on?

    Example of current link:  <a href="http://localhost:1166/imglobal.sitefinity.web/img-insurance/marine-crew-insurance/global-crew-medical-insurance.aspx" title="Global Crew Medical Insurance Overview" sfref="[Sitefinity]1bbba8a3-798a-409c-a75d-4ed10ee6327e">Overview</a>
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    19 Nov 2009
    Link to this post
    Hi Bart Welch,

    We use dynamic links so the localhost domain will be replaced with the actual domain when the website is migrated.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  11. sweety
    sweety avatar
    28 posts
    Registered:
    28 Jun 2010
    04 Aug 2010
    Link to this post
    Hi

    How can I call .htc file in css, it not recognised the relative path...when i put the complete localhost path its working.

  12. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    05 Aug 2010
    Link to this post
    Hi sweety,

    You should not use relative path. Try using a rooted path - starting from the root of the site.

    Regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  13. sweety
    sweety avatar
    28 posts
    Registered:
    28 Jun 2010
    05 Aug 2010
    Link to this post
    Hi Radoslav,

    But if I will use the complete rooted path it  will change on production server , for now when I have  used the following path and its working->

    .png {behavior: url("http://localhost:1635/pe1_final/App_themes/pe1/iepngfix.htc")

    but on production server it will not the same...then what can I do.
  14. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    05 Aug 2010
    Link to this post
    Hello sweety,

    You can use the replace tool. This is the purpose have developed it.

    Sincerely yours,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
14 posts, 0 answered