I'm using a DataFormWebPart with an embedded SoapDataSource. The problem is that SoapDataSource needs to have the full url of the site (http://server/_vti_bin/Myservice.asmx) to work. This makes moving between servers very tricky, as I have to manually update the fields each time. Also as the site collection is to be extended into internal and internet zones this adds another wrinkle. So far I have tried, <% $SPURL:~sitecollection/...%> which does give me a relative URL, and plain ~site/~sitecollection are not replaced. Is there away to embed SPCurrent.Web.URL into the webpart that isn't discarded by SharePoint designer? What other methods are there?

I'm trying to avoid coding this (Which is easily done) so I can avoid adding complexity when none should be needed.

2 Answers 2


I was exploring this last week and have not found any way to make the URL dynamic. I tried the same methods. The only viable solution I found was to create it with jQuery and SPServices, as SPServices uses the current site as the default when hitting the web services.

This comes with the detriment that everything is done client side rather than server side.

  • Yeah that would be an option for simple things, but I need extensive XSLT formatting. Don't think jQuery will make things easier.
    – Jasper
    Commented Feb 13, 2012 at 8:19
  • Yep, I even pinged some of my go to people for DVWPs about it too. Client side was the only way I could make it dynamic (I'm not a Visual Studio guy). Commented Feb 13, 2012 at 13:16
  • Ok, thanks for that. I am a Visual Studio guy, so I'm hoping for a solution in that area.
    – Jasper
    Commented Feb 13, 2012 at 16:08
  • 1
    @Jasper I was one of the guys that looked into this for PirateEric. From what I learned and was told, it's impossible. I wish there was a better answer, but I'm afraid the DVWP isn't that flexible.
    – iOnline247
    Commented Feb 14, 2012 at 2:00

There is a JavaScript Variable on SharePoint pages called _spPageContextInfo. Read more about it here: http://blog.tedpattison.net/Lists/Posts/Post.aspx?ID=9

_spPageContextInfo.siteServerRelativeUrl gives you the relative url of the current Site Collection. _spPageContextInfo.webServerRelativeUrl gives you the relative url of the current web.

Combine that with window.location.href and with a few string operations you can get the current url.

  • Don't see how that would help me. The URL is needed for the soap data source parameter, which is being evaluated serverside as far as I know. The Javascript will only work clientside, after the data has already been retrieved. I don't know if there's a way to change the datasource URL client side, never heard of it.
    – Jasper
    Commented Feb 13, 2012 at 7:30

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.