Pages

IMG

[SharePoint 2010 - Developpement Informations] SPSecurity.RunWithElevatedPrivileges informations

mercredi 9 novembre 2011

SPSecurity.RunWithElevatedPrivileges launch the code with the administrator account of SharePoint.
Thought it could tell you during the execution : "Access denied" or :

UnauthorizedAccessException was unhandled by user code
0x80070005


Make sure you have sufficient privileges to access this resource. If you are attempting to access a file, make sure it is not readonly...

Make sure you re-open a new SPSite inside the SPSecurity.RunWithElevatedPrivileges in order to get the authorization of the administrator.




Example in a feature receiver :




   1: SPSecurity.RunWithElevatedPrivileges(delegate()
   2:             {
   3:                 using (SPSite site = new SPSite(properties.List.ParentWeb.Site.Url))
   4:                 {
   5:                     using (SPWeb web = site.OpenWeb(properties.List.ParentWeb.Url))
   6:                     {
   7:                         SPList List = properties.List;
   8:  
   9:                         try
  10:                         {
  11:                             this.EventFiringEnabled = false;
  12:                             base.ItemAdded(properties);

Aucun commentaire:

 

Blogroll

Jeff ANGAMA, is Office 365 / SharePoint Consultant. Started on MOSS2007 - More Infos Here -

RSE

Rechercher dans ce blog

Where Users are from ?