Workflows and URL links to document items

December 1, 2009

It has been a while since I posted so here is a good one.  For a while I have been struggling with getting a URL for a document item view, it just doesn’t exist as a whole in any SharePoint property.  The kicker is that you have to concatenate a few variables to create any URL you may want to email a user from a workflow (this is my delima).  Say I want to complete a workflow and send a link to the document meta data for user review.  Whoaaa there fella, not so fast…you are using SharePoint after all….

So after countless attempts to create a URL it turns out it is very difficult since each part of the string doesn’t exactly match what I needed to use.  For instance, the site url and web url properties of a worflowproperties object, result in http://hostname/sites/site and the list url includes the same information sites/site/docuemntlibrary (someone said to use the List name property but I almost always create my libraries with a short name then rename it with a longer more descriptive name).

So I am left with a challange, I need to find a property that has the hostname url of the SharePoint web application.  Easy right?  Nope, as our friend Borat would say “Not So Much”.

So the first set in getting your hostname URL is create the following function:
Private Function LocalWebUrl() As String
Dim localUrl As String = Nothing
Using web As SPWeb = workflowProperties.Site.RootWeb
Using site As SPSite = web.Site
For Each altUrl In site.WebApplication.AlternateUrls()
If altUrl.UrlZone = Administration.SPUrlZone.Default Then
localUrl = altUrl.IncomingUrl.ToString
End If
End Using
End Using
Return localUrl
End Function

At this point we have only gotten a short peice of what we need overall.  http://mysharepointurl is basically all we have accomplished, but you do have the ability to get at an alternative URL if needed (perhaps an external namespace or internal alias). 

Second we need the List URL which is fairly straightforward from the workflow properties, something like this:
This provides the site collection and subsite relative URL  “sites/mysite/doclibname”

However this still is not enough to product something that can be clicked by a uers and display their document metadata….we need MORE!

Next we need to grab the remaining url information to pick the proper display form, code would be as follows:
 Finally, tack on a “?ID=” and the workflowProperties.ItemId

So how does this look in the end?  This would get you a document display page in a given workflow….happy SharePointing!
LocalWebUrl() & "/" & workflowProperties.ListUrl & workflowProperties.List.Forms(PAGETYPE.PAGE_DISPLAYFORM).ServerRelativeUrl & "?ID=" & workflowProperties.ItemId


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: