I find it quite annoying that I need to either use controls, or write back-end code to display simple information from SharePoint like the current site’s title or the current user’s display name. And that’s why I developed the SharePoint Expressions; an ASP.NET Expression Builder to simplify access to those values. If you are not familiar with ASP.NET Expressions then you should first take a look at this MSDN article.

  ASP.NET Expressions allow you to evaluate values at runtime using the simple expressions syntax: . For the SharePoint Expressions the expression prefix is SharePoint. Here’s a list of the currently supported expressions (Version 0.9.0.0):

  1. CurrentSiteUrl: Returns the current site collection’s server relative URL
  2. CurrentSiteFullUrl: Returns the current site collection’s full URL
  3. CurrentSiteTitle: Returns the current site collection’s title (HTML Encoded)
  4. CurrentSiteDescription: Returns the current site collection’s description (HTML Encoded)
  5. CurrentWebUrl: Returns the current site’s server relative URL
  6. CurrentWebFullUrl: Returns the current site’s full URL
  7. CurrentWebTitle: Returns the current site’s title (HTML Encoded)
  8. CurrentWebDescription: Returns the current site’s description (HTML Encoded)
  9. CurrentUserDisplayName: Returns the current user’s display name (HTML Encoded)
  10. CurrentUserLoginName: Returns the current user’s login name (HTML Encoded)
  11. CurrentUserEmail: Returns the current user’s e-mail address (HTML Encoded)

As a quick example, lets assume I wanted to display the title of the current site on my ASPX Page or ASCX Control. With the SharePoint Expressions you can achieve that using the following syntax:

SharePoint:CurrentWebTitle%>

<!–span class="hiddenSpellError" pre="">SharePoint:CurrentWebTitl–>

You can of course bind your expressions to any control’s property as long as it is of type System.String.

  SharePoint Expressions are available on CodePlex as a SharePoint 2010 Tools for Visual Studio 2010 solution. They are compatible with SharePoint 2010 only and a Web Application scoped Feature enables them on each web application.

  For the next revision, I am adding a design-time editor, optional URL & HTML encoding for all expressions and support for additional expressions around Lists. You can follow-up work progress on my blog or on twitter @LambrosVasiliou.

Advertisements