I need to add a <link> tag with a dynamic src attribute to a custom masterpage <head> section pointing to a current SPWeb library like this:

<link rel="alternate" type="application/rss+xml" title="RSS Comments" href='http://server/site/mylib/rss.xml'></link>

It should work with SharePoont Foundation and SharePoint Server without developing custom code (like a WebControl) to work in a sandboxed/hosted environment.

I don't have a problem using:

<link rel="alternate" type="application/rss+xml" href='/mylib/rss.xml'></link>

but this is an absolute url and points to the site collection root SPWeb and resolves to:

<link rel="alternate" type="application/rss+xml" href='http://server/mylib/rss.xml'></link>

Hence this will fail if the SPWeb is located at http://server/site/default.aspx.

I've already tried with:

<link rel="alternate" type="application/rss+xml" href='mylib/rss.xml'></link>

But that doesn't work at all creating an invalid link to "_catalogs/masterpage".

I've also tried with $SPUrl but thats only available to SharePoint Server and not Foundation.

I then started to play with:

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

It works without an issue inside a <script> tag (and I assume <style> works too) like this:

<script language="javascript" src='<SharePoint:ProjectProperty Property="Url" runat="server" />/mylib/script.js' type="text/javascript"></script>

and the result is:

<script language="javascript" src='http://server/site/mylib/script.js' type="text/javascript"></script>

However, when I try the following:

<link rel="alternate" type="application/rss+xml" href='<SharePoint:ProjectProperty Property="Url" runat="server" />/mylib/rss.xml'></link>

all thats rendered in the browser HTML source is:

<link rel="alternate" type="application/rss+xml" href="&lt;SharePoint:ProjectProperty Property=&quot;Url&quot; runat=&quot;server&quot; />/mylib/rss.xml" /></link>

Note that using "mylib/rss.xml" just serves as an example to keep my post simple but is not the real path and file (which is more complex).

So the question is, how to format the link tag properly to make it work.

Anybody has an idea what I'm doing wrong?

1 Answer 1


Well, I finally cracked it...

After searching the Interwebs I found two Blog posts and one discussion on the Microsoft online forums:




Unfortunately all of them recommend to use the $SPUrl moniker which is, as I already mentioned, only available to SharePoint Server Standard/Enterprise leaving those who have a SharePoint Foundation hosting package in the cold and dark.

However, those Blog posts pointed me into the right direction and after some experimenting I figured out the correct syntax on my own:

<asp:literal runat="server" Text="&lt;link rel='alternate' type='application/rss+xml' title='RSS Comments' href='"/>
<SharePoint:ProjectProperty Property="Url" runat="server" /><asp:literal runat="server" Text="/mylib/rss.xml" />
<asp:literal runat="server" Text="' /&gt;"/>

Obviously nobody has gotten into the situation of using a SharePoint Foundation hosting package. Even the Wrox book "Professional SharePoint 2010 Branding and User Interface Design" (which I bought extra for this reason) didn't give an answer :(

Posting the answer here so that others can benefit from too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.