Get username from SharePoint User field in List

前端 未结 2 1170
轻奢々
轻奢々 2021-02-06 18:35

I have a custom sharepoint workflow that I\'m developing in Visual Studio. The workflow is running against a document library which has a custom content type connected to it. Th

2条回答
  •  遇见更好的自我
    2021-02-06 18:50

    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; 
     }
    

    Your Code should be like this

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

提交回复
热议问题