Home > Uncategorized > View of a List to filter list items for the current logged in user

View of a List to filter list items for the current logged in user

January 29th, 2007 Leave a comment Go to comments

This has become a serious requirement in two of the projects we are dealing with, so I thought it is worth sharing with the community.

Let’s say, you have a list for which you want to display all the list items Created By the currently logged in user. There are two ways to do it:

A) Through web browser interface: List settings –> Filter –> Choose Created By field and make it equal to [Me]

B) If you want to put it in your site def, things are done a little bit differently.

First of all, the [Me] operator only works on lookup fields bound to the list “user information” and on the built-in system fields (i.e. “created by” OR “modified by”)

Secondly, at the end of the day [Me] is translated to an integer. In order to implement such a functionality you should locate the Schema.xml of the list or document library for which you wish to create this view for and follow these steps:

1) Open Schema.xml

2) Find views element

3) Either create a new view element or insert the following snippet into one of the existing views for which you want to implement the filter:

              <FieldRef Name=”Author” />
              <Value Type=”Integer”>
                <UserID Type=”Integer” />

  This will turn out to an actual T-SQL with where clause and equal operator ( is translated to “=”) at runtime.

4) Save Schema.xml

5) Restart IIS

Now you have the view with a filter on the current logged in user. In next post I will show you how to implement the same functionality using content query web part (CQWP) which is awesome for cases of this kind.

Categories: Uncategorized Tags:
  1. No comments yet.
You must be logged in to post a comment.