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?


Why do you not use SPWorkflowActivationProperties.WebUrl ?

string url = workflowProperties.WebUrl;


string url = workflowProperties.Web.ServerRelativeUrl;
  • Is this also gets the curren sitecollection url? I would like to get the current site collection url. For example: mywebsite.com/sites/RFC – Ola Mar 7 '13 at 13:40
  • 1
    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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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