2009/04/27

CAML query with Person or People and Groups column in Sharepoint 2007 (using in Event Handlers)


I was facing an issue with my simple CAML query where I was trying to filter the Field inside Sharepoint List and supplying value from the properties.AfterProperties of List Item event handler. This field was of Person or to say People and Groups kind of field. Internally inside sharepoint this value is stored as USERID and not as the display name. So I was using a simple CAML builder to build my query and it looked like:

oQuery.Query = "<Where><And><Eq><FieldRef Name='Team_x0020_Member' />" +
"<Value Type='User'>" + properties.Afterproperties[“Team_x0020_Member”].ToString() + "</Value>" + "</Eq>" +
"<Eq><FieldRef Name='Year' /> <Value Type='Choice'>" + properties.AfterProperties["Year"].ToString() +
"</Value> </Eq></And></Where>";


And this never worked for me, then one of my colleagues Madhur Ahuja helped me crack this it was a simple Lookup attribute that was missing, so basically the query should have been:

oQuery.Query = "<Where><And><Eq><FieldRef Name='Team_x0020_Member' LookupId= 'TRUE' />" +

"<Value Type='User'>" + properties.Afterproperties[“Team_x0020_Member”].ToString() + "</Value>" +
"</Eq>" +

"<Eq><FieldRef Name='Year' /> <Value Type='Choice'>" +
properties.AfterProperties["Year"].ToString() +

"</Value> </Eq></And></Where>";


And this never worked for me, so bottom line if you use People and Groups kind of column in Filters always make sure that you use LookupId ='TRUE' attribute in Filters

2009/04/15

SharePoint Security Access Check Codeplex


A colleague of mine just pointed me to this interesting tool ...

http://www.codeplex.com/AccessChecker

Quickly check what objects within a Sharepoint site hierarchy a user has access to. The Access Checker Web Part is a Windows Sharepoint Services Web Part, for use within Windows Sharepoint Services v3 and Microsoft Office Sharepoint Server 2007, that displays a tree view showing permissions on objects for a user scoped to a Site hierarchy. It also has a second mode which will show the permission inheritance of objects within a Site hierarchy.