URL Shortening For SharePoint 2010

I’m pretty sure everybody who is using SharePoint has sent a link to a document in a Document Library to somebody else (in an email message for example). So you probably know that links to documents (or list items) can become pretty long if the document is located in a Document Library on a site deeply buried in a hierarchy. SharePoint is of course not the only platform having this “issue” and the internet already solved it quite some time ago with URL shortening. From Wikipedia:

URL shortening is a technique on the World Wide Web in which a Uniform Resource Locator (URL) may be made substantially shorter in length and still direct to the required page. This is achieved by using an HTTP Redirect on a domain name that is short, which links to the web page that has a long URL. For example, the URL http://en.wikipedia.org/wiki/URL_shortening can be shortened to http://bit.ly/urlwiki or http://tinyurl.com/urlwiki. This is especially convenient for messaging technologies such as Twitter and Identi.ca, which severely limit the number of characters that may be used in a message. Short URLs allow otherwise long web addresses to be referred to in a tweet. In November 2009, the shortened links on one URL shortening service were accessed 2.1 billion times.

So to make a long SharePoint URL short, you can copy the URL to the clipboard, got to a URL shortener, past the long link over there and copy the short URL you get in return back to the clipboard. Works perfectly, but there are quite some tedious steps to go through. Already a long time ago, when SharePoint 2007 was still the rage, I posted some code that automates all these steps. Finally I found some time to update the code to SharePoint 2010 and nicely package it in a Sandboxed Solution, so it works both for SharePoint 2010 deployed on premises as in the cloud on Office 365. The result looks as follows, in the Documents tab of every Document Library, a new item is added to the Share and Track group (the button gets enabled when one document is selected):

When the Get Short Link button is clicked, a call to the Bit.ly URL shortener is made. The short URL is returned, together with a QR code, in a dialog for easy copy/pasting:

You can download the solution (.WSP) from the Get Short Link for SharePoint CodePlex site for easy deployment. Over there you can also find the complete source code, so feel free to enhance and improve! If you feel like sharing back, let me know and I’ll try to include your enhancements in the project. A couple of remarks:

  1. I used the Bit.ly URL shortener because it has a nice API and some cool features (like the QR code generation). You can adjust the source code to use your own Bit.ly account or even another shortener.
  2. The code uses the jQuery Javascript library (because I’m still a lazy developer and I still love jQuery a lot). The latest version of jQuery is included in the solution and automatically deployed.
  3. The solution and the source code are provided “as is” and without warranty of any kind. So please test before you deploy it to your mega big and important SharePoint site. It works on my machine(s). :-)

Side note: if you still follow this blog after a long period of blog-silence: thanks for your patience and welcome back. I won’t make any promises but I really would like to pick up blogging and start contributing again to the fantastic SharePoint community. Feel free to send some comments to encourage me. :-)


Comments have been disabled for this content.