Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How can I work with SPUrl in my code-behind file for master pages and page layouts?

I don't see any access to this in the SharePoint namespaces.

share|improve this question
add comment

3 Answers

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.publishing.webcontrols.spurlexpressionbuilder.aspx ... in your code behind, why not use SPContext to get the url path?

  • SPContext.Current.Web.ServerRelativeUrl [Site]
  • SPContext.Current.Site.ServerRelativeUrl [Site Collection]
share|improve this answer
    
i was looking to make modifications to the SPURL mark-up from code behind, not sure if it's possible or if SPURL derives from anything? thx –  Anonymous Feb 2 '10 at 19:28
1  
check out the MSDN links Jaap and I both posted and you may also want to take a look at this article on creating your own custom expressionbuilder: keirgordon.com/post/… –  Anonymous Feb 2 '10 at 20:30
add comment

If I understand the question right, you should be able to work with the SPUrl expression builder by instantiating it in code, obtaining the expression result, then doing whatever you need to do. Alternatively if you're trying to work with an existing instance, you should be able to get it in the code-behind by ID, though you'd need to pay attention to when in the page lifecycle the actual expression building happens.

Remember also that expression builders are typically only a wrapper anyway (generally around some logic which is more "central" but that you want to make use of in declarative markup), so you could get what you need by using a more direct route with the API e.g. per mike11steven's reply.

If you need an example of a custom expression builder, my SharePoint Config Store project has one.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.