Skip to main content
SharePoint Evolved, Small Steps for a Big Solution

Blog

Go Search
Home
Blog
Wiki
Contact
Themes
TV
  

SharePoint Evolved > Blog > Posts > Simple SharePoint URL Shortener
Simple SharePoint URL Shortener

Based on a request in Linked IN Discussion, I wanted to show how you can create a simple URL shortener using a SharePoint's Links list as well as a custom aspx page.

Step 1

To start off you should create a simple links list in SharePoint.

Once You've created the links list and populated it with the links that you want to share, open up SharePoint Designer.

Step2

Create a blank ASPX Page in SharePoint Designer, place the page at the root directory of your SharePoint site, and name it something appropriate.

You can see here that I've created a blank ASPX page and put it in the root directory as well as given it a name of "redir.aspx".

Step3

You will need to insert a single item view of the Links List you are using on the current page. Find the links list in the Data Source Library in SharePoint Designer.

Select the drop down triggered by the down arrow to the right of the list name, and select "Show Data".

Select only the URL field and Where it says "Insert Selected Fields as" click and select "Single Item View".

This should be your end result when you create the single item view. Go ahead and save your page so you don't lose your progress.

Step 4

Specify The details of the web part. Select the third option from the top where it says "Paging: 1 item(s) per set".

Change it so it only displays one item from the list, mainly because we don't want to send the client multiple places if the ID specified is incorrect or gets deleted.

Next select the third option from the bottom, "Parameters"


Select the "New Paramter" Button.


You'll want to specify a name such as "LinkID". You'll also want to specify the Paramter Source which is Query String, and the Query String Variable is "ID", and you have the options of specifying the default value if no ID is provided, I went ahead and provided the first item of my list.

Now that we have the parameter set up, we need to filter based on the parameter in the url. Select the first option in the properties named "Filter".


Create a filter rule that compares the ID Field to the LinkID parameter as outlined in the picture, and select OK.

Step 5

Now that we have the URL that we want, we need to tell the browser to redirect to the present URL. Find the section that looks like below:

<xsl:template name="dvt_1.rowview">

<tr>

<td>

<table border="0" cellspacing="0" width="100%">

<tr>

<td width="25%" class="ms-vb">

<b>URL:</b>

</td>

<td width="75%" class="ms-vb">

<a href="{substring-before(@URL, ', ')}">

<xsl:value-of select="substring-after(@URL, ', ')"/>

</a>

</td>

</tr>

<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">

<tr>

<td colspan="99" class="ms-vb">

<span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view"></span>

</td>

</tr>

</xsl:if>

</table>

</td>

</tr>

</xsl:template>

Replace it with the following code:

<xsl:template name="dvt_1.rowview">

<tr>

<td>

<xsl:text disable-output-escaping="yes">&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot;>window.location=&quot;</xsl:text>

<xsl:value-of select="substring-before(@URL, ', ')"/>

<xsl:text disable-output-escaping="yes">&quot;;&lt;/script&gt;</xsl:text>

</td>

</tr>
</xsl:template>

Step 6

Save and test it out. You can check out my version here:

http://www.sharepointevolved.com/redir.aspx?ID=1 should redirect to http://sharepointslideshow.codeplex.com/releases/view/38087

Updated May 27th, 2010 – Fixed Testing Link in Step 6


 
 

Technorati Tags

Comments

There are no comments yet for this post.