SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating a Expense management application. I have a page that lists the expenses in the system (they click the expense list to view this).

I now want to change this so that it ONLY displays the logged in users expenses (i don't want user A looking at user B expenses).

I have done this using a web template in visual studio, any modification must be made using visual studio (i cant do this in SP designer as this app will be sent to many clients).

How would i go about approaching this?

share|improve this question
this is in Sharepoint 2010 – user1786107 Nov 7 '12 at 9:16
up vote 2 down vote accepted

You can create a view using SPView class and in query give Author=[Me] and set this view as default view

About the default "All Items" view, set its permission to be viewable to only Administrators or Group with Full Control...

See How to create SPView Programmatically and Programmtically create SPView

Let me know if you need more help!

share|improve this answer
Thanks for the reply. I also came across the SPGridView object while searching google. How does this differ from SPView. In what scenarios would i use one over the other? – user1786107 Nov 7 '12 at 9:33
SPView is similar to making views of a list through UI... However, SPGridView is a SharePoint Control to achieve same look and feel as the Default List View has - They are completely different from each other... – Arsalan Adam Khatri Nov 7 '12 at 9:40

As Arsalan mentioned you can create a SPView which does filter by Me. Here is the CAML query for doing that:

     query.Query = "<Where><Eq><FieldRef Name='Author' /><Value Type='Integer'><UserID Type='Integer' /></Value></Eq></Where>";

Here I have written a blog post which shows how to create a an SPView which does filter by Me:

share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.