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):
- CurrentSiteUrl: Returns the current site collection’s server relative URL
- CurrentSiteFullUrl: Returns the current site collection’s full URL
- CurrentSiteTitle: Returns the current site collection’s title (HTML Encoded)
- CurrentSiteDescription: Returns the current site collection’s description (HTML Encoded)
- CurrentWebUrl: Returns the current site’s server relative URL
- CurrentWebFullUrl: Returns the current site’s full URL
- CurrentWebTitle: Returns the current site’s title (HTML Encoded)
- CurrentWebDescription: Returns the current site’s description (HTML Encoded)
- CurrentUserDisplayName: Returns the current user’s display name (HTML Encoded)
- CurrentUserLoginName: Returns the current user’s login name (HTML Encoded)
- 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:
<!–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.