Search code examples
c#sharepointsharepoint-2007audience

Set "Target Audiences" field with multiple values on a List Item


I am attempting to set the "Target Audiences" field on a list item programmatically. I have been able to set the value programmatically for one audience, but when I attempt to use multiple audiences, SharePoint tries to interpret the value I am setting as a single audience, rather than multiple. I am setting the value using the code below.

listItem[listItem.Fields["Target Audiences"].InternalName] = "Audience One";

I use this code to specify multiple audiences like so:

listItem[listItem.Fields["Target Audiences"].InternalName] = "Audience One; Audience Two";

When I do this, SharePoint tries to interpret the entire string as a single audience, and I get a message when I edit the list item that says "No exact match was found."

Am I using the correct format for specifying multiple audiences for this field, or is there a class that I should be using similar to SPFieldLookupValue?


Solution

  • Just realized I never came back and answered this.

    I ended up storing the names of the audiences in a column attached to each list item, then querying the object model to see if the current user is a member of those audiences. This worked for me because I was pulling the data from the list item in a custom web part, and the user never saw the actual list item.