我正在用 C# 开发一个 Web 部件,它正在读取 SharePoint 列表的内容。我可以检索我需要的所有字段中的值,目标受众字段(使用 AD 安全组)除外。我尝试了各种方法来访问它,例如
string myItem = Convert.ToString(ListItem.properties["Audience"])
但我得到的只是返回空值。当我在 SharePoint 中编辑项目时,我可以看到目标组已存储在该项目的字段中。
如何使用代码检索此字段的内容?
我正在用 C# 开发一个 Web 部件,它正在读取 SharePoint 列表的内容。我可以检索我需要的所有字段中的值,目标受众字段(使用 AD 安全组)除外。我尝试了各种方法来访问它,例如
string myItem = Convert.ToString(ListItem.properties["Audience"])
但我得到的只是返回空值。当我在 SharePoint 中编辑项目时,我可以看到目标组已存储在该项目的字段中。
如何使用代码检索此字段的内容?
尝试不使用 的Properties
,ListItem
而是使用字段本身。
在“目标受众”字段中,您有一些存储为字符串的 GUID,您需要像这样检索这些:
//use the FieldId enumeration for system fields
string audienceID = item[FieldId.AudienceTargeting] as string;
string newID = audienceID.Remove(36); //retrieve just the first guid
Guid audienceGuid = new Guid(newID);
AudienceManager audienceManager= new AudienceManager(SPContext.Current.Site);
Audience audience = audienceManager.GetAudience(guid);
之后你可能想看看audience.GetMembership()
.