add

Wednesday, May 20, 2009

How to set current user in the PeopleEditor via Code

The following code sample will set the currently logged on user to a PeopleEditor:

using (SPWeb web = SPContext.Current.Web)
{
SPUser user = web.CurrentUser;
PickerEntity entity = new PickerEntity();
entity.Key = user.LoginName.ToString();
System.Collections.ArrayList entityArrayList = new System.Collections.ArrayList();
entityArrayList.Add(entity);
PeopleEditorControl.UpdateEntities(entityArrayList);
}

2 comments:

Anonymous said...

thank you very much. it was very useful!

Unknown said...

You make a sever error in your code my friend.The using statement should not be there
this will dispose the current SharePoint context
just remove the using statments