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

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) –  Grumbler85 Mar 11 '13 at 13:34
    
No, ItemURL is returning only: sites/RFC8/Lists/Wijzigingsverzoeken/DispForm.aspx?ID=1 –  KHA Mar 11 '13 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.

share|improve this answer

try

workflowProperties.siteurl

or

HttpContext.Current.Request.ApplicationPath

=

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

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

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.