Take the 2-minute tour ×

is there an hook or interface or whatever that could be used for extending token functionality of sharepoint? For example [Me] token is insufficient for me and I would like to for example develop my own token that can take values from user profiles. Is that possible?

share|improve this question
add comment

1 Answer

There is no way to extend CAML queries. You can see all the existing tokens and possible query elements here:

Well, there are a couple of undocumented CAML Query attributes, but AFAIK nothing that can help in your case.

But there are other possible solutions.

Here I assume that you want to filter a list or a document library. In SharePoint, those objects are rendered via XsltListViewWebPart webpart. This is OOTB webpart, very flexible and powerful.

One solution here would be to set the Query for the XsltListViewWebPart dynamically from your custom webpart deployed to same page.

Another solution, the one I would prefer, is to use parameter bindings. The thing is, you can use parameters in the query. If you open a list view in SPD and select XsltListViewWebPart, there is "Parameters" button on the ribbon.

enter image description here

Using this functionality, you can define one or more parameters. They can come from Query string or from a control on the same page and also from some other places.

enter image description here

Later you can use those parameter in your query:

enter image description here

This will generate the following CAML query:

        <FieldRef Name="FileLeafRef"/>
            <FieldRef Name="Modified"/>
            <Value Type="DateTime">{Param1}</Value>

Additionally, it will generate the parameter binding, like this:

<ParameterBinding Name="Param1" Location="Control(UserProfilePropertyFetcher)" DefaultValue=""/>

So in your case it's quite simple to create a control which will expose a property from the current user profile. Something like this:

public class UserProfilePropertyFetcher
  public string Value
         var serviceContext = SPServiceContext.GetContext(SPContext.Current.Site);
         var upm = new UserProfileManager(serviceContext);

         var userProfile = upm.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);
         return userProfile["PropertyName"].Value.ToString();         


(please replace "PropertyName" with your actual property name)

This control can be deployed either as a delegate control or you can put it straight to the list view page.

P.S. Truth be told, there is already such control in SharePoint, ProfilePropertyValue. Unfortunately, the parameter bingings can only grab values from some public properties of the control, but not from it's output. And unfortunately, ProfilePropertyValue only yields the value of the property to the page, and doesn't expose it to any of it's properties.

share|improve this answer
add comment

Your Answer


