3

I am using a people picker to add users to my event list. I want to show the logged in user in people picker and also the people picker should be read only. How can I achieve this using C#.

1 Answer 1

4

This should work:

 private void SetOwnerUser()
 {
     if (CurrentUser != null)
     {
          // Clear existing users from control
          objPeoplePicker.Entities.Clear();

          // PickerEntity object is used by People Picker Control
          PickerEntity UserEntity = new PickerEntity();

          // CurrentUser is SPUser object
          UserEntity.DisplayText = CurrentUser.Name;
          UserEntity.Key = CurrentUser.LoginName;

          // Add PickerEntity to People Picker control
          objPeoplePicker.Entities.Add(objPeoplePicker.ValidateEntity(UserEntity));

          // This should make People Picker control disable|readonly
          objPeoplePicker.ShowButtons = false;
          objPeoplePicker.AllowTypeIn = false;
     }
 }
4
  • how to do the same if a user does have only right of reading and we want the code to run with elevated privilege. Please provide a solution.
    – Akhilesh
    Aug 10, 2018 at 10:50
  • If you try the above code inside run with elevated privileges, does it work? Aug 12, 2018 at 5:42
  • In my case it wasn't working.
    – Akhilesh
    Aug 13, 2018 at 4:06
  • @Akhilesh please post a separate question, post the code you are trying in the question and tag me in comments, will check Aug 13, 2018 at 5:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.