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);
- Advertisement -