Wednesday 5 March 2014

Get List Item from Sharepoint 2010 using List ID and List Item ID

Get List Item from Sharepoint 2010 using List ID and List Item ID
listItemId= List Item ID
listId= List ID
private string GetListItem(string listItemId, string listId)
{
string strRes = "";
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
{
SPList lst = web.Lists[new Guid(listId)];
SPListItem item = lst.Items[new Guid(listItemId)];
strRes = Convert.ToString(item["NameofEmp"]);
}
}
});
}
catch (Exception ex) { }
return strRes;
}