WebpartsIn the Japanese system[Xiangxiang yaoyun]
By using the target access group, you can set content (such as list or library projects, navigation links, and the entire web part (Web Part: An information module unit consisting of a title bar, framework, and content. A Web part is the basic structure block of a Web Part Page .)) Display to a specific user group. This feature is useful when you want to only provide information related to a specific user group. For example, you can add Web parts to the portal of the Legal Department, which contains a list of valid contracts visible only to this department.
To determine the target access group, you can use one or more of the following:
Region SharePoint Group
Region distribution list
Region Security Group
・ Global Access Group
(The Global Access Group is a rule-based Access Group maintained by the SharePoint administrator .)
As long as the name of the access group is known, it has at least the permissions of the participants (permissions: Authorization for specific operations (such as viewing pages, opening projects, and creating sub-websites .) Anyone can specify the target access group.
CodeImplementation
Using system;
Using system. Collections. Generic;
Using system. text;
Using Microsoft. SharePoint;
Using Microsoft. Sharepoint. administration;
Using Microsoft. Sharepoint. webpartpages;
Using system. Web;
Using system. Web. UI. webcontrols. webparts;
Using Microsoft. Office. server;
Using Microsoft. Office. server. audience;
Namespace consoleapplication2
{
Class Program
{
Static void main (string [] ARGs)
{
Try
{
Using (spsite myspsite = new spsite ("<spsiteurl> "))
{
Spweb sprootweb = myspsite. rootweb;
Splimitedwebpartmanager wpmanager = sprootweb. getlimitedwebpartmanager (sprootweb. url + "/default. aspx", personalizationscope. Shared );
Splimitedwebpartcollection wpcol = wpmanager. webparts;
//TimesCalendar pageSurfaceWebpartsToSearchLocateMarkWebparts
Foreach (system. Web. UI. webcontrols. webparts. webpart webp in wpcol)
{
//AccordingTitleRetrieve objectMarkWebparts, OrSelectOther uniqueIdentifier
If (webp. Title = "<thetitleofyourwebparts> ")
{
String audienceid = string. empty;
String audiencename ="<GlobalAccessGroup Name>";
Servercontext context = servercontext. getcontext (myspsite );
Audiencemanager audmanager = new audiencemanager (context );
Audiencecollection audcol = audmanager. audiences;
//Get globalAccessGroupGuid
Foreach (AUDIENCE audience in audcol)
{
If (audience. audiencename. Equals (audiencename ))
{
Audienceid = audience. audienceid. tostring ();
Break;
}
}
//CheckGlobalAccessWhether the group exists, noThenThrowError
If (string. isnullorempty (audienceid ))
{
Throw new applicationexception (
"<ErrorInformation>",
Null );
}
//GlobalAccessAllGuidIn multiple cases.PleaseSeparated by commasIsolation
String [] globalaudienceids = new string [] {audienceid };
//SecurityGroupSave as followsIn
String [] dldistinguishednames = new string [] {"cn = group1, Cn = users, Dc = spdev, Dc = com", "cn = group2, Cn = users, dc = spdev, Dc = com "};
// SharepointgroupToGroupnameIn the form
String [] Using pointgroupnames = new string [] {"<using pointgroupname1>", "<using pointgroupname2> "};
//UseMossProvided methods to formatAccessGroup, needUsing Microsoft. Office. server. Audience
String webpartaudiences = audiencemanager. getaudienceidsastext (
Globalaudienceids,
Dldistinguishednames,
Sharepointgroupnames );
Webp. authorizationfilter = webpartaudiences;
//AftercareLocationLi, alsoXuSome are redundant....
Webp. databind ();
Wpmanager. savechanges (webp );
Break;
}
}
Wpmanager. Dispose ();
Sprootweb. Update ();
}
}
Catch (applicationexception myexception)
{
<GlobalAccessThe specified group does not exist.HourOfErrorManagement>
}
Catch (exception E)
{
<ErrorManagement>
}
}
}
}
Reference http://stsadm.blogspot.com/2008/04/programmatically-setting-web-part.htmlsetting-web-part.html