Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

2 Answers 2

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
add comment

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: http://sharepointnadeem.blogspot.in/2012/02/create-view-to-filter-items-by-me.html

share|improve this answer
add comment

Your Answer

 
discard

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.