views:

20

answers:

1

Given a list name "User Data" and setting Item-Level Permissions to "Only their own" for read and edit.

How can I as a site owner see only my own items on that list when using the SharePoint Object Model? Basically I want to store a small amount of user maintainable data and display that through a web part.

SPList list = web.Lists["User Data"];
if (list != null)
{
    foreach (SPListItem item in list.Items)
    {
        // How to limit this for admin accounts to not see everything
        // Maybe using SPQuery instead or something?
    }
}

I guess another interesting question is, how do I tell if the current user has the "Manage Lists" permission and do some custom query?

+1  A: 

Site Owner are a very special permission (actually they are not a permission) that tells SharePoint to ignore the security model and just show everything.

So you will need to check some properties on the list items to filter.

JD
Do you think it would be reasonable to check SPWeb.AllRolesForCurrentUser and only filter for users that would see everything?
Goyuix
It depends... if only a small portion of my users are Site Owners then yes. If most users are Site Owners then no.
JD