Access Denied – SharePoint code execution
When doing certain code operations in SharePoint like getting list of templates will lead to “Access Denied” exceptions. For such instances we can wrap the code within the following lines to execute code with elevated privileges.
SPSecurity.RunWithElevatedPrivileges(delegate() { //Code goes here });