SharePoint高级内容--访问群体对象模型的开发之二

本文介绍如何使用SharePoint Portal Server管理访问群体,包括创建复杂的访问规则、获取成员信息及显示用户所属群体等实用技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

4、为访问群体添加复杂的基于AND 、OR和()的规则
我们可以使用括号与AND ,OR共同作用,组合出更复杂的规则来。 Sharepoint Portal Server的对象模型可以支持最多三层括号的嵌套。
注意:如果一个访问群体对应复杂的规则,您就不能在Web管理页面中查看或编辑其属性了。不过不用担心,您仍可以在Web管理页面中查看其包含的成员。

下面是个组合出复杂规则的例子

<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->TopologyManagertopology=newTopologyManager();
PortalSiteportal
=topology.PortalSites[newUri("http://server_name")];
PortalContextcontext
=PortalApplication.GetContext(portal);
AudienceManagerAudMgr
=newAudienceManager(context);
Audiencea
=null;
boolruleListNotEmpty=false;
try
{
a
=AudMgr.Audiences["Engineer"];
}
catch(AudienceArgumentExceptionex)
{}
ArrayListaRules
=a.AudienceRules;
if(aRules==null)
{
aRules
=newArrayList();
}
else
{
ruleListNotEmpty
=true;
}
try
{
if(ruleListNotEmpty)
{
aRules.Add(
newAudienceRuleComponent(null,"AND",null));
}
AudienceRuleComponentr0
=newAudienceRuleComponent(null,"(",null);
aRules.Add(r0);

AudienceRuleComponentr1
=newAudienceRuleComponent("FirstName","Contains","a");
aRules.Add(r1);

AudienceRuleComponentr2
=newAudienceRuleComponent(null,"AND",null);
aRules.Add(r2);

AudienceRuleComponentr3
=newAudienceRuleComponent("WorkEmail","Contains","DepA.com");
aRules.Add(r3);

AudienceRuleComponentr4
=newAudienceRuleComponent(null,")",null);
aRules.Add(r4);

AudienceRuleComponentr5
=newAudienceRuleComponent(null,"OR",null);
aRules.Add(r5);

AudienceRuleComponentr6
=newAudienceRuleComponent(null,"(",null);
aRules.Add(r6);

AudienceRuleComponentr7
=newAudienceRuleComponent("FirstName","Contains","b");
aRules.Add(r7);

AudienceRuleComponentr8
=newAudienceRuleComponent(null,"AND",null);
aRules.Add(r8);

AudienceRuleComponentr9
=newAudienceRuleComponent("WorkEmail","Contains","DepB.com");
aRules.Add(r9);

AudienceRuleComponentr10
=newAudienceRuleComponent(null,")",null);
aRules.Add(r10);
a.AudienceRules
=aRules;
a.Commit();

}
catch(AudienceExceptione)
{}

5、获取访问群体的成员

下面的代码将访问群体的成员的WindowsNT系统名称显示了出来。

<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->TopologyManagertopology=newTopologyManager();
PortalSiteportal
=topology.PortalSites[newUri("http://server_name")];
PortalContextcontext
=PortalApplication.GetContext(portal);
AudienceManagerAudMgr
=newAudienceManager(context);
try
{
ArrayListmemarray
=AudMgr.Audiences["Engineer"].GetMembership();

foreach(UserInfooinmemarray)
{
Console.WriteLine(o.NTName);
}
}
catch(AudienceExceptione)
{}

6、显示用户所隶属于的访问群体

已此类推,我们也可以显示一个用户所隶属于德所有访问群体。

<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->TopologyManagertopology=newTopologyManager();
PortalSiteportal
=topology.PortalSites[newUri("http://server_name")];
PortalContextcontext
=PortalApplication.GetContext(portal);
AudienceManagerAudMgr
=newAudienceManager(context);
try
{
//传入一个Windows帐号名来获取隶属于的访问群体组。
//如果要获取当前用户的隶属访问群体组,只要不指定任何参数直接GetUserAudienceIDs()就可以了
ArrayListaudienceIDNames=AudMgr.GetUserAudienceIDs("domain_name\\alias");
ArrayListaudienceNames
=newArrayList();


for(inti=0;i<audienceIDNames.Count;i++)
{
AudienceNameIDarrTemp
=(AudienceNameID)audienceIDNames[i];
audienceNames.Add(arrTemp.AudienceName);
Console.WriteLine(audienceNames[i].ToString());
}

}
catch(AudienceExceptione)
{}


7、得到规程操作符的显示名称和内部名称

可以用下面的代码看看这些操作符在Web管理页面中怎么叫。

<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->TopologyManagertopology=newTopologyManager();
PortalSiteportal
=topology.PortalSites[newUri("http://server_name")];
PortalContextcontext
=PortalApplication.GetContext(portal);
AudienceManagerAudMgr
=newAudienceManager(context);

ArrayListOpList
=AudMgr.AudienceOperatorList;

for(intlist=0;list<OpList.Count;list++)
{
Console.WriteLine(list.ToString());
Console.WriteLine(
"Name:{0}",((AudienceOperator)OpList[list]).OperatorName);
Console.WriteLine(
"DisplayName:{0}",((AudienceOperator)OpList[list]).OperatorDisplayName);
}


8、得到规则操作符左侧操作数允许使用的名称

可以用下面的代码看看可以用作规则操作符左侧操作数的所有内容。包括在Web管理页面中显示的名称和我们在编程时使用的内部名称。上面有提到的“Everyone”,“DL”就包括在这里,还有好多活动目录中有的属性,值得细细去查看。

<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->TopologyManagertopology=newTopologyManager();
PortalSiteportal
=topology.PortalSites[newUri("http://server_name")];
PortalContextcontext
=PortalApplication.GetContext(portal);
AudienceManagerAudMgr
=newAudienceManager(context);

ArrayListLeftContentList;
LeftContentList
=AudMgr.AudienceLeftContentList;

for(intlist=0;list<LeftContentList.Count;list++)
{
Console.WriteLine(list.ToString());
Console.WriteLine(
"Name:"+((AudienceLeftContent)LeftContentList[list]).Name);
Console.WriteLine(
"DisplayName:"+((AudienceLeftContent)LeftContentList[list]).DisplayName);
Console.WriteLine(
"DataType:"+((AudienceLeftContent)LeftContentList[list]).DataType);
Console.WriteLine(
"DataLength:"+((AudienceLeftContent)LeftContentList[list]).DataLength);
Console.WriteLine(
"bProperty:"+((AudienceLeftContent)LeftContentList[list]).bProperty);
}

(完)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值