且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从列表中的 SharePoint 用户字段获取用户名

更新时间:2023-02-12 19:54:09

参考这个 文章 关于如何从字段中获取用户详细信息.

Refer to this Article on how to get the User Details from the Field.

public static SPUser GetSPUser(SPListItem item, string key) {
     SPFieldUser field = item.Fields[key] as SPFieldUser;

     if( field != null) {   
         SPFieldUserValue fieldValue = field.GetFieldValue(item[key].ToString()) as SPFieldUserValue; 

         if(fieldValue != null)     
            return fieldValue.User; 
      }
      return null; 
 }

你的代码应该是这样的

SPUser spUser=GetSPUser(splistItem,"Owner");
String sUserName=(spUser!=null)?spUser.UserName:null;