Sunday, January 25, 2009

How to query in a sharepoint List

the following function will take an User Name as a parameter and will return the section for the user--------------------------------------------------------------


private string GetSectionByUserName(string userName)
{
string section = string.Empty;
SPList userList = SPContext.Current.Web.SiteUserInfoList;
SPQuery query = new SPQuery();

query.Query = "<Where><Eq><FieldRef Name='Author'/><Value Type='Text'>"+ userName + "</Value></Eq></Where>";

SPListItemCollection itemCollection = userList.GetItems(query);

if (itemCollection.Count > 0)
{
section = itemCollection[0]["Section"].ToString();
}
return section;
}

No comments:

Post a Comment

5 Strategies for Getting More Work Done in Less Time

Summary.    You’ve got more to do than could possibly get done with your current work style. You’ve prioritized. You’ve planned. You’ve dele...