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 added a ContentEditorWebPart to an Element file in visual studio. I want to get the current site url and place it in the content block (between the cewp:Content tags).

How would i do this?

Please note i am in a sandboxed solution so this is the only way i can add a ContentEditorWebPart. How do i reference the current site url using the code below?

  AllUsersWebPart WebPartZoneID="FullPage1" WebPartOrder="0"
                WebPart xmlns="" xmlns:cewp=""
                AssemblyMicrosoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c/Assembly
                TitleStructral Site Text/Title
                  This is some content with a link. a href=""/a
share|improve this question
up vote 1 down vote accepted

You could add some js script and use the _spPageContextInfo object.

 This is some content with a link. <a id="siteUrl">click here</a>   
<script language="JavaScript">
    document.getElementById('siteUrl').setAttribute('href', _spPageContextInfo.webServerRelativeUrl);
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.