开发者

how to retrieve target security group for a SharePoint list item?

I am developing a web part in C# which is reading the contents of a SharePoint list. I can retrieve the values in all t开发者_运维百科he fields I need, except the Target Audience field (which uses AD security groups). I have tried various ways to access this e.g.

string myItem = Convert.ToString(ListItem.properties["Audience"])

but all I get is null returned. I can see that a target group has been stored in the fueield for thwe item when I edit the item in SharePoint.

How can I retrieve the contents of this field using code?


Try not using the Properties of the ListItem, but the fields themselves.

In the "Target Audience" field you have some GUIDs stored as strings, these you need to retrieve like so:

//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);

afterwards you might want to look at audience.GetMembership().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜