Showing posts with label PeopleEditor Control. Show all posts
Showing posts with label PeopleEditor Control. Show all posts

PeopleEditor Control must also accept ADGroups

PeopleEditor Control must also accept ADGroups:

Aspx Page:
<%@ Register TagPrefix="wssawc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<
wssawc:peopleeditor id="UserPickerRequestedFor" runat="server" allowempty="False"height="20px" multiselect="true" selectionset="User" showcreatebuttoninactivedirectoryaccountcreationmode="True"validatorenabled="True" width="300px"></wssawc:peopleeditor>

PeopleEditor control can easily be set to accept users as well as AD groups. Refer an excellent link here.


Changed to :


<wssawc:peopleeditor id="UserPickerShipTo" runat="server" allowempty="False" height="20px"multiselect="true" selectionset="User,SecGroup" showcreatebuttoninactivedirectoryaccountcreationmode="True"validatorenabled="True" width="300px"></wssawc:peopleeditor>

Get multiple users from PeopleEditor and update column of type “People and Group” in SharePoint List

Get multiple users from PeopleEditor and update column of type “People and Group”.

Aspx Page:
<%@ Register TagPrefix="wssawc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" %>

<wssawc:peopleeditor id="UserPickerRequestedFor" runat="server" allowempty="False"
height="20px" multiselect="true" selectionset="User" showcreatebuttoninactivedirectoryaccountcreationmode="True"
validatorenabled="True" width="300px"></wssawc:peopleeditor>

Aspx.Cs Page:

ArrayList arrUsers = new ArrayList();
PickerEntity UserEntity = new PickerEntity();
SPFieldUserValueCollection fieldUsrValues = new SPFieldUserValueCollection();                  
int UsrCount = UserPicker.Accounts.Count;
for (int j = 0; j < UsrCount; j++)
{
    UserEntity = (PickerEntity) UserPicker.Entities[j];
    string  UserAcctName = UserEntity.Description;
    Hashtable PeopleEditorData = UserEntity.EntityData;
    string strUserLogin = UserEntity.Key;
    arrUsers.Add(strUserLogin);
}
foreach (object obj in arrUsers)
{
   string login = obj.ToString();
   SPSecurity.RunWithElevatedPrivileges(delegate()
   {
    using (SPSite elevatedSite = new SPSite(web.Site.ID))
    {
      elevatedSite.AllowUnsafeUpdates = true;
      SPWeb elevatedWeb = elevatedSite.OpenWeb(web.ID);
      {
        elevatedWeb.AllowUnsafeUpdates = true;
        SPUser User = elevatedWeb.EnsureUser(login);
        SPFieldUserValue val = new SPFieldUserValue(web,User.ID, User.Name);
        fieldUserValues.Add(val);
       }
      }
     });
   }
reqItem["UserNames"] = fieldUserValues;

Get multiple users from People Editor and update column of type “People and Group” – Method2

if (UserPickerOwners.Accounts.Count > 0)
{ reqItem["SiteOwner"] = GetUsersFromPeoplePicker(); }


protected SPFieldUserValueCollection GetUsersFomPeoplePicker(string usrType)
{
  ArrayList arrUsersMain = new ArrayList();
  ArrayList arrUsersSec = new ArrayList();
  PickerEntity UserEntity = new PickerEntity();
  SPFieldUserValueCollection fieldUsrValues = new SPFieldUserValueCollection();
  int UsrCount = 0;

  arrUsersMain = UserPickerOwners.Entities;
  UsrCount = UserPickerOwners.Accounts.Count;

  for (int j = 0; j < UsrCount; j++)
  {
    UserEntity = (PickerEntity)arrUsersMain[j];         
    string strUserLogin = UserEntity.Key;
    arrUsersSec.Add(strUserLogin);
  }      

   foreach (object obj in arrUsersSec)
   {
    string login = obj.ToString();
    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
      using (SPSite elevatedSite = new SPSite(web.Site.ID))
      {
          elevatedSite.AllowUnsafeUpdates = true;
          SPWeb elevatedWeb = elevatedSite.OpenWeb(web.ID);
          {
               elevatedWeb.AllowUnsafeUpdates = true;
               SPUser User = elevatedWeb.EnsureUser(login);
               SPFieldUserValue val = new SPFieldUserValue(web, User.ID, User.Name);
               fieldUsrValues.Add(val);
           }
         }
      });
    }
   return (fieldUsrValues); 

}


Get single user from PeopleEditor and update column of type “People
and Groups”.

Aspx Page:
<%@ Register TagPrefix="wssawc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" %>

<wssawc:peopleeditor id="UserPickerRequestedFor" runat="server" allowempty="False"
height="20px" multiselect="true" selectionset="User" showcreatebuttoninactivedirectoryaccountcreationmode="True"
validatorenabled="True" width="300px"></wssawc:peopleeditor>

Aspx.Cs Page:
PickerEntity UserEntity = new PickerEntity();
int usrCount = UserPicker.Accounts.Count;
for (int i = 0; i < usrCount; i++)
  {
   UserEntity = (PickerEntity)UserPicker.Entities[i];
   string  userAcctName = UserEntity.Description;
   Hashtable peopleEditorData = UserEntity.EntityData;
   string strUserLogin = UserEntity.Key;
   SPSecurity.RunWithElevatedPrivileges(delegate()
   {
   using (SPSite elevatedSite = new SPSite(web.Site.ID))
   {
    elevatedSite.AllowUnsafeUpdates = true;
    SPWeb elevatedWeb = elevatedSite.OpenWeb(web.ID);
    {
       elevatedWeb.AllowUnsafeUpdates = true;
       SPUser user = elevatedWeb.EnsureUser(strUserLogin);
    }
   }
 });
SPUser usrToADD = web.AllUsers[strUserLogin];
reqItem["ReqMgr"] = usrToADD;