public static SPFieldUserValue GetUserValue(string name)
{
SPFieldUserValue userColl = new SPFieldUserValue();
SPSecurity.RunWithElevatedPrivileges(delegate
{
using (var site = new SPSite(_rootUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList splist1 = web.Lists["用户信息列表"];
SPQuery query = new SPQuery();
query.Query = @"<Where>
<Eq>
<FieldRef Name='Title' />
<Value Type='Text'>" + name + @"</Value>
</Eq>
</Where>";
SPListItemCollection userSpListColl = splist1.GetItems(query);
if (userSpListColl.Count == 1)//如果判断非空,害怕出现多个的问题
{
userColl = new SPFieldUserValue(web, userSpListColl[0].ID, userSpListColl[0].Title);
}
}
}
});
return userColl;
}