Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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:

http://mywebsite.com/sites/RFC/Lists/Wijzigingsverzoeken/DispForm.aspx?ID=28

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

sites/RFC/Lists/Wijzigingsverzoeken/DispForm.aspx?ID=28

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

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

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

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Why do you not use SPWorkflowActivationProperties.WebUrl ?

string url = workflowProperties.WebUrl;

or

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: mywebsite.com/sites/RFC –  KHA 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; –  KHA Mar 11 '13 at 12:08

Your Answer

 
discard

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.