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

It seems you cannot use the ~site or ~siteCollection tokens in an Element.xml when you deploy as a Sandboxed Solution. Has anyone ever seen this behaviour?

Code snippet:

><sharepoint:SoapDataSource runat="server" SelectUrl="~site/blog/_vti_bin/lists.asmx" InsertUrl=""

The ~site token gets replaced by an empty string (i.e. disappears) instead of the site URL upon deployment. Why?

share|improve this question
up vote 3 down vote accepted

The ~Site and ~SiteCollection tokens are part of the Publishing dll which is not allowed in the Sandbox. So they cannot be referenced from your code or aspx pages. However, the tokens can be used with the Elements.xml. I have used them in the following way:

<CustomAction Location="ScriptLink" ScriptSrc="~Site/SiteAssets/myScript.js"/>

share|improve this answer
I have the idea that the replacement only works in node attributes. In my case, I need the replacement inside the content of the AllUsersWebPart (inside a CDATA block), there it doesn't seem to be working. – Jasper Feb 10 '12 at 10:38

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.