SharePoint’s SPList class contains the GetItems method which is used to query the contents of a SharePoint list. Rather than iterating through all of the list’s items, the GetItems method allows you to specify a collaborative application markup language (CAML) query to return just the collection of items in which you are interested. It is like sending a SQL query to the SharePoint list. Clearly this is an indispensible method to know about when dealing with any non-trivial list.

One would expect that in order for a call to GetItems to return data, the user invoking the code would need only Read permissions to the list. However, I have run into situations where a user had Read permissions to a list but the call to GetItems returned no data. I had already validated that the query worked by invoking the call to GetItems from another user.

In those situations I could not get a call to GetItems to return any data unless the user had at least Contribute permissions to the SharePoint web site that contained the list. This was the case even if the user had Contribute permissions to the list. Read permission to the SharePoint site or list were insufficient.

I have not yet had time to nail down exactly what circumstances or configuration settings trigger this behavior. If others have seen this behavior and have more insight, I’d love to hear about it. For now, if you have a GetItems call that should be returning data but is not, before spending hours or days  changing around your code, try invoking the call from a user who has Contribute permissions to the site.

Technorati Tags: WSS,SharePoint,MOSS,SPList,GetItems