How to Get SPUser Detail Programatically on ListItem Field
using (SPSite site = new SPSite("http://servername/"))
{
using (SPWeb web = site.OpenWeb())
{
SPList List=web.Lists["Voucher"];
foreach(SPListItem ListItem in List.Items)
{
SPFieldUser ownerField =ListItem.Fields.GetField("ColumnName") as SPFieldUser;
SPFieldUserValue ownerValue = ownerField.GetFieldValue(ListItem[ownerField.Id].ToString()) as SPFieldUserValue;
SPUser owner = ownerValue.User;
string ownersEmail = owner.Email;
Console.WriteLine("user Name"+ListItem["ColumnName"].ToString());
Console.WriteLine("Users Email Id....."+ownersEmail.ToString());
Console.WriteLine("User Name .........." + owner.Name);
Console.WriteLine("User Id ............." + owner.ID);
Console.WriteLine("User Login........." + owner.LoginName);
Console.Read();
}
}
}
No comments:
Post a Comment