I want to set a user to SharePoint people picker. The user will have only read permission hence code will be run with elevated privileges. I have written below code

 SPSecurity.RunWithElevatedPrivileges(delegate ()
 {
            SPSite site = SPContext.Current.Site;
            SPWeb web = SPContext.Current.Web;
            using (SPSite mySite = new SPSite(site.ID))
            {
                using (SPWeb myWeb = mySite.OpenWeb(web.ID))
                {
                    try
                    {
                        #region loading Profile Data

                        mySite.AllowUnsafeUpdates = true;
                        if (peRequestFor.Accounts.Count == 0)
                        {


                           peRequestFor.CommaSeparatedAccounts = userLoginName;             
                            peRequestFor.Validate();                              
                            peRequestFor.Accounts[0] = userLoginName;

                        }
                    }
                }

         }
}

But Still, I am getting an error in place of people picker control in form as The control is not available because you do not have the correct permissions. Just for sake of tagging I tagged 'client people picket' but it is aspx control. Kindly update question and tag appropriate tags if anyone has privileges.

  • Request you if anyone providing negative points to the problem asked also provide justification for the same, This is my genuine concern. Request you to edit the question if I am missing anything or written incorrectly. – Akhilesh Aug 11 at 4:41
  • @Arsalan Adam Khatri Please help me in resolving the issue. – Akhilesh Aug 13 at 8:49

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.