从列表中的 SharePoint 用户字段获取用户名 [英] Get username from SharePoint User field in List

查看:36
本文介绍了从列表中的 SharePoint 用户字段获取用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在 Visual Studio 中开发的自定义共享点工作流.工作流针对具有自定义内容类型连接的文档库运行.内容类型包括用户查找字段(所有者").

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. The content type includes a user lookup field ("owner").

我正在尝试让我的工作流程将任务分配给所有者"查找字段.但是,我只能获取用户的显示名称,而不是帐户用户名.

I'm trying to have my workflow assign a task to the "owner" lookup field. However, I've only been able to get the display name for the user, not the account username.

有人可以帮忙吗?

推荐答案

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

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;

这篇关于从列表中的 SharePoint 用户字段获取用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆