4

I have a master page with tabs. The tabs are defined by the following sitemap file:

<siteMap>
    <siteMapNode title="Home" url="~/" >
        <siteMapNode title="Schedule" url="~/Pages/Tab2.aspx"/>      
        <siteMapNode title="Deliverables" url="~/Pages/Tab3.aspx"/>
        <siteMapNode title="My Items" url="~/Pages/Tab4.aspx"/>
        <siteMapNode title="Management" url="~/Pages/Tab5.aspx"/>
        <siteMapNode title="Working Docs" url="~/Pages/Tab6.aspx"/>
    </siteMapNode>
</siteMap>

The problem is that on my subsites, clicking on a tab keeps taking me back to the root. For example, I want the schedule link to go to http://Server/Subsite/Pages/Tab2.aspx. Instead, what I am getting is http://Server/Pages/Tab2.aspx. I read that having a tilde at the beginning of the link would solve this problem but it doesn't.

DL.
  • 65
  • 1
  • 3
  • 7

3 Answers3

13

I spent HOURS looking for the answer to this question, and it turns out there IS one, it's just annoying. You can use the ProjectProperty tag in WSS sites AND MOSS sites, and one of the possible parameters for ProjectProperty gives you the subsite's URL.

<SharePoint:ProjectProperty Property="Url" runat="server"/>

That outputs a string literal with the value of the subsite URL. So, for example, you can do this (note that you need to use single-quotes for the src='' or href='' attribute of the actual HTML tag):

<a href='<SharePoint:ProjectProperty Property="Url" runat="server"/>/pages/Tab2.aspx'>

Hope it helps! For a listing of other possible values for ProjectProperty, check out this guy's page (which is where i found my original answer!)

adrienne
  • 707
  • 1
  • 8
  • 24
9

I was looking for an answer to do this for a long time... I want to package my site as a Site Template and having absolute URLs was not an option... I need them to be relative to what ever the site URL is... whether it is at the root of MOSS or a sub-site deep down in the structure...

I found the following to work:

Script Tags:

<script type="text/javascript" src='<asp:Literal runat="server" 
               Text="<% $SPUrl:~Site/appBin/js/jquery.min.js %>" />'></script>

Style sheet (Method suggested above by user385947):

<link rel="stylesheet" type="text/css" 
       href="<% $SPUrl:~Site/appBin/css/jquery-ui.css %>" />

Hope this helps others...

Paul T.
  • 608
  • 1
  • 6
  • 11
  • Worked for me. Interestingly though, for stylesheets, it works without the ``. For ` – F.P Dec 16 '13 at 14:43
  • Can you explain how to implement this in a master.page? (for an ASP.NET 4.5 website?) – Danimal111 Mar 28 '14 at 19:31
  • Sorry for the late response... In working with Sharepoint, I inserted this in the portion of the Master page... Note that when working with sharepoint designer, it will mangle up your code above... I think this normally happens when you open the file... After fixing it to look like the above, saving should maintain the format. – Paul T. Apr 06 '14 at 18:02
2

You're looking for the ~site token, here's a list of the URL tokens custom to WSS.

Preston Guillot
  • 6,493
  • 3
  • 30
  • 40
  • 1
    ~site is not working for me. The link becomes http://Server/~site/Pages/Tab2.aspx. Maybe this doesn't work in a sitemap file? – DL. Oct 28 '09 at 16:35
  • Hmm, I posted under the assumption that the token replacement was being done in one of the SharePoint HTTPHandlers, which means it should work in the site map, but after looking at this SO post: http://stackoverflow.com/questions/337781/creating-custom-url-tokens-in-asp-net-a-la-moss it appears the tokens are actually parsed somewhere else. Regardless the ~ token is always relative to the web app root, not the current site/site collection in SharePoint. You may need to implement your own site map provider to get the functionality you're really looking for, sorry for the misleading answer. – Preston Guillot Oct 28 '09 at 18:23