Build SharePoint URL Links Programmatically

I like to use Query Strings as well as building my own navigation links inside SharePoint.  The problem when you create your own menu buttons on a page is that if you use absolute encoded URLs they break if you move the site or rename a parent in the URL.  This takes a little work on the URLs that SharePoint gives you.

Here is how I use XSLT to build links, I am showing the rowview template:

<xsl:template name="dvt_1.rowview">
<xsl:variable name="BaseURL" select="@FileDirRef"/>
<xsl:variable name="LocalURL" select="substring-before(ddwrt:UrlDirName(string($BaseURL)), '/Lists')"/>
<table border="0" cellspacing="0" width="100%" style="text-align:left;">
<td class="NavbarCell" colspan="4">
<li><a href="{$LocalURL}/Pages/home.aspx?Release={@Release}">Home</a></li>
<li><a href="{$LocalURL}/Pages/wb.aspx?Release={@Release}">Workbooks</a></li>
<li><a href="{$LocalURL}/Pages/ccb.aspx?Release={@Release}">CCB</a></li>
<li><a href="{$LocalURL}/Pages/dev.aspx?Release={@Release}">Development</a></li>
<li><a href="{$LocalURL}/Pages/qa.aspx?Release={@Release}">QA</a></li>
<li><a href="{$LocalURL}/Pages/ca.aspx?Release={@Release}">C&amp;A</a></li>
<li><a href="{$LocalURL}/Pages/docs.aspx?Release={@Release}">Docs</a></li>
<li><a href="{$LocalURL}/Pages/fielding.aspx?Release={@Release}">Fielding</a></li>
<li><a onfocus="OnLink(this)" href="{@projuid}" target="_blank">IMS</a></li>

Note:  Release is a query string I send between these pages


Popular posts from this blog

SharePoint Designer 2013 Approval Workflow with Comments

Change SharePoint server hostname and Web Application Names

SharePoint Search - Content Processing Pipeline Failed to Process the Item