Recently, the project used the poopleeditor control. The following information was collected from the Internet and sorted out.
Simple usage
<% @ Register tagprefix = " SharePoint " Namespace = " Microsoft. Sharepoint. webcontrols " Assembly = " Microsoft. Sharepoint, version = 12.0.0.0, culture = neutral, publickeytoken = 71e9bce111e9429c " %> <% @ Register tagprefix = " Utilities " Namespace = " Microsoft. Sharepoint. Utilities " Assembly = " Microsoft. Sharepoint, version = 12.0.0.0, culture = neutral, publickeytoken = 71e9bce111e9429c " %> <% @ Import namespace = " Microsoft. SharePoint " %> <SharePoint: peopleeditor id = " Peopleeditor1 " Runat = " Server " Selectionset = " User " Validatorenabled = " True " Allowempty = " False " Multiselect = " True " />
The above is the usage of SharePoint 2007. Generally, you must register the control.
Selectionset --- the range that can be selected first. It can generally be a group, a person, or an ad Security Group.
Validatorenable ---- if it is set to true, it will be automatically verified. When refreshing
Allowsempty -- meaning that null is allowed
Get user selection Value
Arraylist list = Leleeditor1.resolvedentities; // Get ID and display name Foreach (Microsoft. Sharepoint. webcontrols. pickerentity P In List ){ String Userid = P. entitydata [ " Spuserid " ]. Tostring (); String Displayname = P. entitydata [ " Displayname " ]. Tostring ();} // Get account Arraylist selectedaccoutlist = Leleeditor1.accounts; String Selectedaccouts2 = leleeditor1.commaseparatedaccounts;
Set the Control Value
Leleeditor1.commaseparatedaccounts =@"Jyserver \ spsadmin, jyserver \ Administrator";
If multiple values are allowed, you can put them in a set, as shown below:
String[] User = userpicker. commaseparatedaccounts. Split (New String[] {","}, Stringsplitoptions. None)
SharePoint 2010 can reference the following DLL files
<% @ Register tagprefix ="SharePoint"Namespace ="Microsoft. Sharepoint. webcontrols"Assembly ="Microsoft. Sharepoint, version = 14.0.0.0, culture = neutral, publickeytoken = 71e9bce111e9429c"%>
--Note: In fact, in SharePoint 2010, you can reference the registration in the previous section 07. It can be used in development!
Complex usage
The following is an instance that can allow groups, security groups, and people. You can select multiple instances!
<SharePoint: peopleeditor id ="Pplapprovers"Width ="300px"Selectionset ="User, DL, secgroup, spgroup"Multiselect ="True"Allowtypein ="True"Isvalid ="True"Runat ="Server"/>
Set Value
Private Arraylist approversarray; Private Spfielduservaluecollection approverscollection; approverscollection = (Spfielduservaluecollection) item ["approvers"]; pickerentity entity = New Pickerentity (); approversarray = New Arraylist (); Foreach (Spfielduservalue In Approverscollection) {entity = New Pickerentity (); entity. Key = Spfielduservalue. lookupvalue; entity = Pplapprovers. validateentity (entity); approversarray. Add (entity);} pplapprovers. updateentities (approversarray );
Value
Approversarray = Pplapprovers. resolvedentities; // use the following code to save the data back to the list item: approverscollection = New Spfielduservaluecollection (); spuser user; spgroup group; Foreach (Pickerentity entity In Approversarray ){ If (Entity. entitydata [ " Principaltype " ]. Tostring () = " Sharepointgroup " ) {Group = Web. sitegroups [entity. Key]; approverscollection. Add ( New Spfielduservalue (Web, group. ID, group. loginname ));} Else { // Handles securitygroup, distribution list and user User = Web. ensureuser (entity. Key); approverscollection. Add ( New Spfielduservalue (Web, user. ID, user. loginname) ;}} item ["approvers"] = Approverscollection;
Ui settings
Generally, if multiple options are allowed, the options are wide and large, and the selected buttons are displayed in the lower right corner. When we use the buttons for queries, so we have to limit its height and other aspects to make it look pretty. The following is an instance that can be selected multiple times and displayed in one row.
<TD style = " Width: 400px; text-align: Left; Height: 28px; line-Height: 28px; " > <SharePoint: peopleeditor id = " Pdname " Selectionset = " User, spgroup " Multiselect = " True " Runat = " Server " Rows = " 1 " Width = " 100% " Placebuttonsunderentityeditor = " False " /> </TD>
Where
Placebuttonsunderentityeditor = "false": Set the browser button to the right.
Rows = "1" means only one row in height.
In general, you can set its bordercolor = "gray" borderwidth = "1", which is quite nice!
It is best to set validatorenabled = "true"
I used the query report table above. For details, refer to the preceding complex usage values, as shown in my project.
List < String > Userlist = New List < String > (); # Region Get user list Spweb = Spcontext. Current. Web; arraylist approversarray = Pdname. resolvedentities; Foreach (Pickerentity entityIn Approversarray ){ If (Entity. entitydata [ " Principaltype " ]. Tostring () = " Sharepointgroup " ) {Spgroup Group = Web. sitegroups [entity. Key]; grouplist. Add (Group );} Else {Spuser user = Web. ensureuser (entity. Key); userlist. Add (user. loginname );}} Foreach (Spgroup g In Grouplist) {spusercollection users = G. users; Foreach (Spuser u In Users ){ If (!Userlist. Contains (U. loginname) {userlist. Add (U. loginname );}}} # Endregion
Other types, such as secroup and DL, do not know how to fetch them for the moment. They can be extracted from complicated ones and filled up when used!
The following is the reference address:
Http://blogs.catapultsystems.com/jdunagan/archive/2011/08/24/sharepointpeopleeditor-basics.aspx
Http://www.cnblogs.com/jianyi0115/archive/2007/11/10/955452.html
Http://blog.csdn.net/li_shengwangso/article/details/6623479