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 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: 

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

Here you can see what the merge is doing: + sites/RFC8/Lists/Wijzigingsverzoeken/DispForm.aspx?ID=1 

How can I get the website url without absolute path? Something like this:

share|improve this question
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 Mar 11 '13 at 13:34
No, ItemURL is returning only: sites/RFC8/Lists/Wijzigingsverzoeken/DispForm.aspx?ID=1 – Ola Mar 11 '13 at 20:08

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.

share|improve this answer






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

string finalUrl = HttpContext.Current.Request.ApplicationPath + ItemURL;
share|improve this answer

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.