Showing posts with label People Picker. Show all posts
Showing posts with label People Picker. Show all posts

Monday, July 7, 2014

update aspx or any file through Powershell

I had this problem of SharePoint people picker issue, where in the People picker restricted to particular SharePoint group was having UI problem .Problem was that when you try to search users a popup open with the users in that SharePoint group for you to be selected .

Problem is that the Height of the people picker popup in IE10 was very small as below.
It was working fine in IE9,IE11 and IE10 quirks mode


The files in use are picker.aspx and pickerdialog.aspx .

There were two solutions

Solution-1 : Edit the picker.aspx



·         Locate the div with ID = ‘resultcontent ‘and add style property to it. Set the min-height value from inside the style property like below.

<div id='resultcontent' style="min-height:300px" class="ms-pickerresultdiv">
 
 
Solution-2 : Edit the Pickerdialog.master 
·         In the Meta tags section, set the “X-UA-Compatible” to “IE=EmulateIE9” to make it look like below.
 
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />
Here in this option the page is rendered in IE9 mode  

Client chose the solution-2 and they wanted to automate this using the PowerShell ,hence I wrote the below PowerShell command to take backup of the current pickerdialog.aspx and update the tag in the file which is present in 15 hive, this ps1 has to run in all web front-end server
Below is the PowerShell command
 
 
 
 
Write-host -ForegroundColor Green "Updating Pickerdialog.master file started .........!!"
Write-host -ForegroundColor Green "Creating backup of current file ........."
$a =(Get-Date).ToString('MM-dd-yyyy hh-mm-ss')
$filename = "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\pickerdialog-{0}.master" -f $a
copy "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\pickerdialog.master" $filename
Write-host -ForegroundColor Green "Backup of current file completed ........."
(Get-Content "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\pickerdialog.master") |
Foreach-Object {$_ -replace "<meta http-equiv=`"X-UA-Compatible`" content=`"IE=10`"/>", "<meta http-equiv=`"X-UA-Compatible`" content=`"IE=EmulateIE9`"/>"} |
Set-Content "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\pickerdialog.master"
Write-host -ForegroundColor Green "Updating Pickerdialog.master file completed ........."
pause
 
 
 
 

Monday, August 19, 2013

Add data to people picker in Visual webpart programatically - sharepoint 2010

Add the People picker field in the ascx file as below

 <SharePoint:PeopleEditor runat="server" ID="peoplePickerID" MultiSelect="true" 
SelectionSet="User" />

in the code behind on page load write the logic to fill teh people picker from a list having a
people/group type column.


ArrayList PickerEntities = new ArrayList(); 
SPFieldUserValueCollection fieldUserValueCollection = (SPFieldUserValueCollection)item["PeopleGroupTypeColumnDispName"];

            foreach (SPFieldUserValue spuserval in fieldUserValueCollection)
            {
                SPUser userToassign = spuserval.User;
                PickerEntity entity = new PickerEntity();
                PeopleEditor pepEditor = new PeopleEditor();
                entity.EntityData["AccountName"] = spuserval.User.LoginName;
                entity.EntityData["SPUserID"] = spuserval.User.ID;
                entity.EntityData["Email"] = spuserval.User.Email;
                entity.Key = spuserval.User.LoginName;
                entity.Description = spuserval.User.LoginName;
                entity.DisplayText = spuserval.User.Name;
                entity = pepEditor.ValidateEntity(entity);
                entity.IsResolved = true;
                PickerEntities.Add(entity);
            }

peoplePickerID.UpdateEntities(PickerEntities);

 *item["PeopleGroupTypeColumnDispName"];--> is list column of people/group type


Have a look at other post about client people picker of Sharepoint 2013
Client people picker-Sharepoint 2013 



 

Tuesday, July 30, 2013

Add data from People Picker control into people/Group column field of a list in Sharepoint Visual Webpart

The below code can be used in visual webpart where in you have a requirement to pick the data from people picker field and add the data to people or group column of any list


 SPFieldUserValueCollection customer = new SPFieldUserValueCollection();
                    foreach (PickerEntity enity in pepPickCustomer.ResolvedEntities)
                    {
                        SPUser user = SPContext.Current.Site.RootWeb.EnsureUser(enity.Key);
                       
customer .Add(new SPFieldUserValue(SPContext.Current.Site.RootWeb, user.ID, user.Name));

                    }

Later to add data to list

item["PeopleGroupColumName"] = customer;


*
pepPickCustomer is the ID of Client people picker control which is a new type of people picker control available Sharepoin 2013.

Friday, July 5, 2013

Add data to People picker field programatically -Sharepoint 2013

I had a requirement where in the visual webpart had a people picker control .I used the client people picker which is a new and betta control in Sharepoint 2013.This control had to be binded with the data coming from a people picker field of some list.Here is the code to achieve it




SPFieldUserValueCollection reviewers = (SPFieldUserValueCollection)Item["PeoplePickerFieldColumnDisplayName"];
List<PickerEntity> reviewersEntity = new List<PickerEntity>();
foreach (SPFieldUserValue spuserval in reviewers){

SPUser userToassign = spuserval.User;
PickerEntity entity = new PickerEntity();
PeopleEditor pe = new PeopleEditor();
entity.EntityData["AccountName"] = spuserval.User.LoginName;
entity.EntityData["SPUserID"] = spuserval.User.ID;
entity.EntityData["Email"] = spuserval.User.Email;
entity.Key = spuserval.User.LoginName;
entity.Description = spuserval.User.LoginName;
entity.DisplayText = spuserval.User.Name;
entity = pe.ValidateEntity(entity);
entity.IsResolved =true;
 reviewersEntity.Add(entity);
}
PeoplePickerControlName.AddEntities(reviewersEntity);



*"item " is a SPListItem type


in ascx file client people picker looks like

<SharePoint:ClientPeoplePicker runat="server" ID="PeoplePickerControlName" Required="true" ValidationEnabled="true"
                        InitialHelpText="text"
                        VisibleSuggestions="3"
                        Rows="1"
                        AllowMultipleEntities="true"
                        CssClass="ms-long ms-spellcheck-true" /> 

Have a look at other post about  people picker of Sharepoint 2010
People Picker -Sharepoint 2010 

Monday, June 17, 2013

Get data from People Picker(ClientPeoplePicker) through code

There is a new control in sharepoint 2013 named ClientPeoplePicker.Which is a very good control loads the user prediction on the client side using a hidden div .


To get the data from this control on the server side use the code below


string a = "";

ArrayList resolve = pepPickcker.ResolvedEntities;
foreach (PickerEntity entity in resolve){
a += entity.Key+";";   //Key will give you the login name you can use other attributes}


*pepPickcker is the control ID