I´m searching for a function in C# where I can open a Sharepoint List with a specific user. The user who runs the webpart have no permission for the SharePoint list. So my idea was to open the list with a admin user in the code behind.

Is there a possibility?


You might want to check the SPSecurity.RunWithElevatedPrivileges method to give user an admin privileged to the list.

Impersonation in SharePoint

Guid id = SPContext.Current.Site.ID;                
SPUser user = SPContext.Current.Web.EnsureUser("Loginname");              
  using (SPSite site = new SPSite(ID,user.UserToken))
      using (SPWeb web = site.OpenWeb())
         //write code for further operation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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