I have a custom workflow in VS. I would like to merge an url. The problem is I am in an site collection with the name RFC. I see the absolute path 2 times when I merge like below:

ItemURL = currentItem.ParentList.DefaultDisplayFormUrl + "?ID=" + HttpUtility.UrlEncode(currentItem.ID.ToString());

string finalUrl = workflowProperties.WebUrl + ItemURL;

This results: http://mywebsite.nl/sites/RFC8/sites/RFC8/Lists/Wijzigingsverzoeken/DispForm.aspx?ID=1 

The problem is, you see 2 times the absolute path : sites/RFC8

Here you can see what the merge is doing:

http://mywebsite.nl/sites/RFC8/ + sites/RFC8/Lists/Wijzigingsverzoeken/DispForm.aspx?ID=1 

How can I get the website url without absolute path? Something like this: http://mywebsite.nl/

  • Isn't ItemURL enough? Because normally a Server-Relative URL should do... (if you want to pass it via mail or else, there is the UrlMapping in the WebApplication-Class, which can be used)
    – TGlatzer
    Commented Mar 11, 2013 at 13:34
  • No, ItemURL is returning only: sites/RFC8/Lists/Wijzigingsverzoeken/DispForm.aspx?ID=1
    – Ola
    Commented Mar 11, 2013 at 20:08

2 Answers 2


You have already stored a server relative url in the ItemUrl variable.

// this returns "sites/RFC8/Lists/Wijzigingsverzoeken/DispForm.aspx?ID=1 "
ItemURL = currentItem.ParentList.DefaultDisplayFormUrl + "?ID=" 
             + HttpUtility.UrlEncode(currentItem.ID.ToString());

The SPSite object offers a method called MakeFullUrl that "Returns the full URL for the specified server-relative URL". That means that you only need a valid SPSite instance to be able to call the aforementioned method and obtain the full url you need.

You can use the Site property from the workflowProperties object or, for a more general approach, just reuse the currentItem instance you already have. So, for example you can use:

string finalUrl = currentItem.ParentList.ParentWeb.Site.MakeFullUrl(currentItem.ParentList);

Just a final notice: as pointed out by this blog post (link), MakeFullUrl DOES take in account Alternate Access Maps. Most of the time this is exactly what you want, but sometimes it could be a problem. If that is the case, please ensure that you use a SPSite that has been constructed from an url relative to the specific access map you want to use.







ItemURL = currentItem.ParentList.DefaultDisplayFormUrl + "?ID=" + HttpUtility.UrlEncode(currentItem.ID.ToString());

string finalUrl = HttpContext.Current.Request.ApplicationPath + ItemURL;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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