SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using sharepoint 2010 and have created a workflow in vs. In this workflow I create some tasks and fill the title, bodytext and assign it to a user or group. In the bodytext I add an hyperlink as "a href". I try to get the link from the current item. The problem is that sometimes the link is not correct because the hostname is missing. This is the code:

SPListItem currentItem = workflowProperties.Item;
    string itemURL = currentItem.ParentList.DefaultDisplayFormUrl + "?ID=" + HttpUtility.UrlEncode(currentItem.ID.ToString());

    workflowProperties.Web.Site.WebApplication.Sites[0].Url + itemURL

Sometimes is works and than this is the hyperlink:

And sometimes it the link is not working, and is it like this:


It looks like the problem is inside this piece of code:


Does someone know where the problem is? Or what the best practice is to get the sharepoint website url?

share|improve this question
up vote 2 down vote accepted

Why do you not use SPWorkflowActivationProperties.WebUrl ?

string url = workflowProperties.WebUrl;


string url = workflowProperties.Web.ServerRelativeUrl;
share|improve this answer
Is this also gets the curren sitecollection url? I would like to get the current site collection url. For example: – Ola Mar 7 '13 at 13:40
use workflowProperties.Site.Url or workflowProperties.Site.ServerRelativeUrl depend on you needs. The Site is an object that represents current site collection. – Alexander Mar 7 '13 at 13:45
WHy this one gives sometimes an empty string?? string url = workflowProperties.Web.ServerRelativeUrl; – Ola Mar 11 '13 at 12:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.