SharePoint List’s Person or Group field value as c# SPUser objet

added by muraligolla
10/1/2010 2:01:00 AM

1 Kicks, 1388 Views

Casting the list's Person or Group field value into SPUser object. # using(SPSite spSite = new SPSite("site URL")) # { # using(SPWeb spWeb = spSite.OpenWeb()) # { # SPList spList = spWeb.Lists["List Name"]; # SPListItem spListItem = spList.GetItemByID(itemID); # string currentValue = spListItem["Person or Group field name"].ToString(); # SPFieldUser userField = (SPFieldUser)spWeb.Lists["List Name"].Fields.GetField("Person or Group field name"); # SPFieldUserValue fieldValue = (SPFieldUserValue)userField.GetFieldValue(currentValue); # SPUser user = fieldValue.User; # # OR # # SPFieldUserValue spFieldUserValue = new SPFieldUserValue(web , Convert.ToString(projectItem["Person or Group field name"])); # SPUser user = spFieldUserValue.User; # } # }


0 comments