C# – How to only see “the” items on a list when using item Level permissions as a site owner

cmosssharepoint

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?

Best Answer

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.

Related Topic