For a big customer we had to create about 80 different audiences, which should be deployed on multiple server (test, acceptance, production, etc.). Each audience have rules to describe if a user is part of the audience or not. Creating audiences is very easy, just provide a name and description. Rules however need some more attention.
Time to write a script for that! So, first of al, I searched the SDK for some more information about the way rules are used within the audiences. Basically you can add rules programatically like this:
using (SPSite site = new SPSite("http://servername"))
{
ServerContext context = ServerContext.GetContext(site);
AudienceManager AudMgr = new
AudienceManager(context);
AudienceCollection ac = AudMgr.Audiences;
Audience a = null;
bool ruleListNotEmpty = false;
try
{
a = AudMgr.Audiences["John and Joe Connection"];
}
catch (AudienceArgumentException
ex)
{
//your exception handling code here
}
ArrayList aRules = a.AudienceRules;
if (aRules == null)
{
aRules
= new ArrayList();
}
else
{
ruleListNotEmpty
= true;
}
try
{
//if
the rule is not emply, start with a group operator "AND" to append
if (ruleListNotEmpty)
{
aRules.Add(new AudienceRuleComponent(null, "AND", null));
}
AudienceRuleComponent
r0 = new AudienceRuleComponent(null, "(", null);
aRules.Add(r0);
AudienceRuleComponent
r1 = new AudienceRuleComponent("FirstName", "Contains", "John");
aRules.Add(r1);
AudienceRuleComponent
r2 = new AudienceRuleComponent(null, "AND", null);
aRules.Add(r2);
AudienceRuleComponent
r3 = new AudienceRuleComponent("WorkEmail", "Contains", "example.com");
aRules.Add(r3);
AudienceRuleComponent
r4 = new AudienceRuleComponent(null, ")", null);
aRules.Add(r4);
AudienceRuleComponent
r5 = new AudienceRuleComponent(null, "OR", null);
aRules.Add(r5);
AudienceRuleComponent
r6 = new AudienceRuleComponent(null, "(", null);
aRules.Add(r6);
AudienceRuleComponent
r7 = new AudienceRuleComponent("FirstName", "Contains", "Joe");
aRules.Add(r7);
AudienceRuleComponent
r8 = new AudienceRuleComponent(null, "AND", null);
aRules.Add(r8);
AudienceRuleComponent
r9 = new AudienceRuleComponent("WorkEmail", "Contains", "someexample.com");
aRules.Add(r9);
AudienceRuleComponent
r10 = new AudienceRuleComponent(null, ")", null);
aRules.Add(r10);
a.AudienceRules
= aRules;
a.Commit();
}
catch (AudienceException
e)
{
//Your
exception handling code here
}
}
}
Quite a flexible way to deal with rules. However, there are three parts that you have to deal with:
This way you can add change and construct audiences easily.
Related Posts:
>>AKS Update
>>MOSS (internet) licensing changed!
>>WSS 2.0 and SPS 2003 Service Pack 3 (SP3) released
>>MS Information Worker Conferences
>>New Version of Ontolica Search available (3.2)
>>TamTam.SharePoint.AudienceCreator 1.0 released on codeplex
>>New community site focusing on Enterprise Search
>>SharePoint 2007 limitations
>>CruiseControl Webparts v1.2
>>SharePoint Solution (WSP) creation tool
>>MOSS 2007: Best Practices when upgrading
>>Biometric Authentication For SharePoint
Month Archives:
Top Tags:
social software social networking .NET mashable Sharepoint ASP.NET Web 2.0 Web2.0 Startups Community News Search Marketplace General Software Development AJAX Windows Vista Microsoft Visual Studio myspace People Powered! YouTube Silverlight Vista Featured News MOSS C# Events Google WPF MOSS 2007 Office 2007 Web
@2007 All rights Reserved |