Create Shortened (‘TinyURL’) links from your SharePoint Workflow

Related Products

PDF Converter

PDF Converter


When we released the Muhimbi URL Shortener for SharePoint, we knew that even though it was a great product, we couldn’t please everyone. For example, all generated Short URLs point to list items’ Form View, from where the item can be edited, deleted or opened in an external application. This behaviour is by design, but some customers prefer to have the short URL point directly to the file, e.g. a Generated PDF.

In this article we describe how to generate a short URL from a SharePoint Designer workflow with full control over which view the URL points to using both MuSH and the Workflow Power Pack.

A quick introduction for those not familiar with the product: The Muhimbi Workflow Power Pack for SharePoint allows custom C# or VB.NET code to be embedded in SharePoint Designer Workflows without the need to resort to complex Visual Studio based workflows, the development of bespoke Workflow Activities or long development cycles.

The solution presented below creates a short URL for the current item the workflow is acting on. An optional value can be specified in Parameter 1 to control if the generated URL points to the file or display form using the ‘displayform’ and  ‘file’ values.

Create the workflow as follows:

  1. Download and install the Muhimbi Workflow Power Pack for SharePoint.

  2. Download and install the Muhimbi URL Shortener for SharePoint.

  3. We need to be able to access functionality in the Muhimbi.SharePoint.URLShortener assembly. Add this reference to the relevant Web Application using the Workflow Power Pack Central Administration screens as described in the Administration Guide.

  4. Make sure you have the appropriate privileges to create workflows on a site collection.

  5. Create a new workflow using SharePoint Designer.

  6. On the Workflow definition screen associate the workflow with the list or library of your choice, tick the box next to ‘ Automatically start this workflow when a new item is created’ and proceed to the next screen.

  7. Click the Actions button and insert the Execute Custom Code action .

  8. Click this variable and create a new Workflow Variable named shortURL using string as the type.

  9. Click parameter 1 and enter file or displayform or leave it empty to default to displayform.

  10. Insert the following C# based code by clicking this code.

    using Muhimbi.SharePoint.URLShortener;

    // ** Where do we want the shortened URL to point to?

    string target = MyWorkflow.Parameter1 == null ? "displayform" : (String) MyWorkflow.Parameter1; string sourceURL = null; // ** Point the short URL to the file or the file's info form switch (target.ToLower()) {     case "file":         sourceURL = String.Format("{0}/{1}", MyWorkflow.Web.Url, MyWorkflow.Item.Url);         break;     case "displayform":         sourceURL = String.Format("{0}/{1}?ID={2}",                      MyWorkflow.Web.Url,                                     MyWorkflow.List.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url,


    break;     default:         throw new ArgumentException("Unknown target specified, use 'file' or 'displayform'."); } // ** Add a description to the short URL, amend if necessary string description = "Generated from workflow"; // ** Carry out the shortening process ShortenedURL shortURL = Muhimbi.SharePoint.URLShortener.URLShortener.CreateURLViaWebService(                             MyWorkflow.Site.WebApplication.Id, sourceURL, description); // ** Return the fully qualified URL back to the workflow MyWorkflow.ReturnValue = shortURL.GetFullyQualifiedShortURL();

  11. Click the Actions button, select Log to History List, click this message, set the Source to Workflow Data and the Field to shortURL.

  12. Close the Workflow Designer and add an item to your list or library to trigger the workflow.

  13. Once the workflow has finished, click the Completed link to see the generated short URL.


Naturally this is just a simple example. Under normal circumstances you would do something more useful with the shortURL workflow variable, for example embed it in an email.

Labels: Articles, News, PDF Converter, Workflow

Have a Question?
We’re Always Happy to Help.

© Muhimbi Ltd. 2008 - 2024
This website uses cookies to ensure you get the best experience. Learn more