PANVEGA’s Blog

DotNet Development, SharePoint Customizing, Silverlight, MS Infrastructure and other tips and tricks

Getting user login from the PeopleEditor via Code

Posted by PANVEGA on February 1, 2008

Assuming you have a people editor control defined like below:

<wssawc:PeopleEditor AllowEmpty=”false”  ID=”myPeopleEditorControl” runat=server SelectionSet=”User” MaximumEntities=”1″ MultiSelect=”false” AllowTypeIn=”false” Width=’500px’ />

The following code sample will get you the currently logged on user’s login from the PeopleEditor control:

ArrayList peEntities = myPeopleEditorControl.Entities;
PickerEntity pickEn = (PickerEntity)peEntities[0];
stringLogIn = pickEn.Key;

This comes handy when you want to create an SPUser context out of the entities kept in the PeopleEditor control. For example:

private SPUser GetUser(string logIn)

{
SPUser user = this.workflowProperties.Web.SiteUsers[logIn];
return user;
}

Don’t forget Required Field Validation on your people editor control if you want the code not to break on you.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: