If somebody like the post and its helpful in your work then, add comments.

Friday, July 3, 2009

Using SPQuery in SharePoint object model

SPSite rootSite = new SPSite("http://mossvs2008");
SPWeb SubSite = rootSite.AllWebs["LeaveSite"];
string strTitleValue = string.Empty;
Console.WriteLine("Please enter Employee ID");

strTitleValue = Console.ReadLine();
SPList SPList = SubSite.Lists["Employee List"];
SPQuery query = new SPQuery();
query.Query = <Where><Eq<>FieldRef Name='Title' /><Value Type='Text'>"+strTitleValue+">/Value>>/Eq></Where>";>/

SPListItemCollection itemcol = SPList.GetItems(query);
string strTitle = string.Empty;
string strDesignation = string.Empty;
string strEmployeeName = string.Empty;

foreach (SPListItem item in itemcol)
{
strTitle = item["Title"].ToString();
strDesignation = item["Designation"].ToString();
strEmployeeName = item["Employee Name"].ToString();
}
Console.WriteLine("Employee ID.........");
Console.WriteLine(strTitle);
Console.WriteLine("Employee Designation.");
Console.WriteLine(strDesignation);
Console.WriteLine("Employee Name........");
Console.WriteLine(strEmployeeName);

No comments:

Post a Comment

Post a Comment