Archive for the ‘People Picker’ Category


Normally, the SharePoint People Picker shows all the users from the Active directory, local users etc whose profiles are imported. But in some case we need to restrict the users to select only a group of people.

For example, what if i don’t want the AD users to be displayed in the people picker. There is no meaning in removing the AD user profiles from SSP.

Here comes the trick. Using stsadm command tool, I am able to specify that, people picker should use only the users who are provided access in the site collection.

Here the 2 simple steps goes,

  1. Provide permissions to the site collection for the users whom you wish to display in the people picker.
  2. Run this command stsadm -o setproperty –url http:// –pn peoplepicker-onlysearchwithinsitecollection –pv yes

Now, whomsoever the users you provide permission to the site collection will only appear in the people picker too.

Advertisements

I was working with the People Editor Control and realized there are a couple weird things you need to do before you can read values into the control and save values into a list.  Here is a samples related to saving multiple/single user details into a people or groups column in a list.


SPFieldUserValueCollection UserCollection = new SPFieldUserValueCollection();
string[] UsersSeperated = pplEditor.CommaSeparatedAccounts.Split(‘,’);
if (UsersSeperated.Length > 0)
{
foreach (string UserSeperated in UsersSeperated)
{
SPUser User = web.SiteUsers[UserSeperated];
SPFieldUserValue UserName = new SPFieldUserValue(web, User.ID, User.LoginName);
UserCollection.Add(UserName);
}

item[“Name”]=UserCollection

This way we can store single or multiple user names in a People or Groups column from a people editor group.


I used SharePoint People Editor control in custom asp.Net web part.I wanted to check for required field. I have tried using the property Allow Empty, but unfortunately it doesn’t work. I have used a Required field validator. Luckily it works to some extent. But the problem starts if there is any post back happening on the page. After the post back, it takes the value to be empty even if there is an entry in the control.

I got to get a javascript that  checks if the control is empty and stores the results of the validation in the IsValid property of the ServerValidateEventArgs object.

Here is the script and a custom validator we need to use to check e\whether the people editor control is empty or not.

<script type=”text/javascript” language=”javascript”>
function CheckBusinessExcellence(source, arguments)

{
if (aspnetForm.ctl00_PlaceHolderMain_pplBusinessExcellence_downlevelTextBox.value == “”)
arguments.IsValid = false;
else
arguments.IsValid = true;

}

</script>


<sharepoint:peopleeditor ValidatorEnabled=”true” autopostback=”true” rows=”1″ width=”300″ enablebrowse=”true”
id=”pplBusinessExcellence” multiselect=”False” runat=”server” />


<asp:CustomValidator ID=”rfvBusinessExcellence” runat=”server” ControlToValidate=”” ErrorMessage=”You must specify a value for this required field.” Enabled=”false” ClientValidationFunction=”CheckBusinessExcellence”>
</asp:CustomValidator>



And in a more simpler way, I found the normal Required Field validator works fine for me.

<sharepoint:peopleeditor validatorenabled=”true” allowempty=”false”  rows=”1″ width=”300″ enablebrowse=”true”
id=”pplBusinessExcellence” multiselect=”False” runat=”server” />

<asp:RequiredFieldValidator EnableClientScript=”true” ID=”rfvBusinessExcellence” ControlToValidate=”pplBusinessExcellence” runat=”server” ErrorMessage=”You must specify a value for this required field”></asp:RequiredFieldValidator>


Hope it helps.


Last week while deployment we faced an issue in people picker. We needed to give permission to the users site from different domains. But it failed to resolve entities from a domain while other’s are working fine.

When working on this issue, we got a suggestion from a Microsoft support team. Create a security group in the frontend server and add the required users to it (Here you will get all the users from every domain). Use this group to give permission in the SharePoint site.

Of course this is a better way and Microsoft suggests this way of adding user permissions which mostly we fail to do.

But investigating more on this why this issue have occured for only a domain we found there is some issue with the network. For people picker to work we need some ports to be open from the other domain. Here is an article reading about it.


If you are using a people picker control of sharepoint in your web page or if you want to update a People and group column of a list item, you cant update the item by using a string value (in my case loginUser).

string loginUser= Convert.ToString(ViewState[“accountname”]);
item[“To”] = loginUser;
Item.Update();

This above code will throw an error for invalid datatype.
So we have to input a SPUser object to the item which can be done as below.

string loginUser= Convert.ToString(ViewState[“accountname”]);
SPUser user = site.Users[loginUser];
item[“To”] = user;
Item.Update();