Scenario
We have a SharePoint list with the column Manager which is Person or group column. We need to filter or query this list programmatically to get items where certain user is the manager
Solution
SPList list = ... // initialize your list
SPQuery query = new SPQuery();
SPUser user = ... // initialize SPUser object
string sUserName = user.Name; // you just need to know user display name in SharePoint
query.Query = string.Format("<Where><Contains><FieldRef Name='Manager' /><Value Type='User'>{0}</Value></Contains></Where>", sUserName);
SPListItemCollection items;
items = list.GetItems(query);
We have a SharePoint list with the column Manager which is Person or group column. We need to filter or query this list programmatically to get items where certain user is the manager
Solution
SPList list = ... // initialize your list
SPQuery query = new SPQuery();
SPUser user = ... // initialize SPUser object
string sUserName = user.Name; // you just need to know user display name in SharePoint
query.Query = string.Format("<Where><Contains><FieldRef Name='Manager' /><Value Type='User'>{0}</Value></Contains></Where>", sUserName);
SPListItemCollection items;
items = list.GetItems(query);
Comments
Post a Comment