Microsoft SharePoint Server 2010 allows you to set content targets based on access group rules, Sharepoint groups, and Microsoft Exchange distribution list (DL) membership. In addition, Sharepoint Server 2010 provides the ability to set content targets at the list item level, not just at the list level.
This code example shows how to create a rule-based access group that can be set as the content target.
Note
In this example, only the access group is created. No access group is collected and no rules are added. You can use the user interface or object model to add rules, and then use the user interface to collect access groups. The object model does not support collecting access groups.
Before running this sample code, add the following references to the Microsoft Visual Studio project:
Microsoft. Office. server. dll
Microsoft. Office. server. userprofiles. dll
Microsoft. Sharepoint. dll
System. Web. dll
Using system; using system. collections. generic; using system. text; using Microsoft. sharepoint. administration; using Microsoft. office. server. audience; using Microsoft. sharePoint; using Microsoft. office. server; using system. web; namespace audienceconsoleapp {class program {static void main (string [] ARGs) {try {using (spsite site = new spsite ("http: // MOSS: 8001 ")) {spservicecontext context = spservicecontext. getcontext (SITE); audiencemanager audmanager = new audiencemanager (context); audiencecollection AC = audmanager. audiences; audience A = NULL; string saudname = "moss2010 rule access group"; string sdescription = "moss2010 rule access group"; try {A = ac. create (saudname, sdescription );
Console. writeline ("created successfully ");
Console. Read ();
} catch (AudienceDuplicateNameException e) { //Your exception handling code here } catch (AudienceException e1) { //Your exception handling code here } } } catch (Exception exception) { Console.WriteLine(exception.ToString()); Console.Read(); } } }}
Open the target access group of a list in http: // MOSS: 8001.