Answered by:
Access denied error on SiteCollection Restore Method using Sharepoint object model

Question
-
The following function used to Restore the SiteCollection backup programatically. i am getting Access denied error at restore method.
i have checked the application pool user , Checked the Security validation is: off in Central administrator . changed the authentication mode to : Kerberos. did every thing but still getting
Access denied error.same code for backup method working in Sharepoint 2010.
below code is working in sharepoint 2007.
its giving error in Sharepoint 2010. Please help me.
string RootSiteUrl = SPContext.Current.Site.Url;
string RootWebUrl = SPContext.Current.Web.Url;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPSite RootSite = new SPSite("RootSiteUrl");
SPWeb RootWeb = RootSite.OpenWeb();
// RootSite .AllowUnsafeUpdates = true;RootWeb.AllowUnsafeUpdates = true;
SPWebApplication WebApp = RootWeb.Site.WebApplication;
SPSiteCollection SiteColl = WebApp.Sites;//bool formDigestEnabledStatus = WebApp.FormDigestSettings.Enabled;
//WebApp.FormDigestSettings.Enabled = false; //if uncomment this getting Access denied Error alsostring SiteUrl = "http://server:888/Sites/Mysitename";
string Filepath = "C:/SharepointBackup/Backup.bak";
SiteColl.Restore(SiteUrl, Filepath, true); // Access denied Error
// WebApp.FormDigestSettings.Enabled = formDigestEnabledStatus;});
Wednesday, March 23, 2011 12:40 PM
Answers
-
Got it - for my situation anyway.
Even though it seems counter-intuitive, I logged into the server as the Farm Admin and opened the Mgt Shell as "Administrator."
for reference the exact command (sanitized) was
restore-spsite -identity http://server/sitename -path c:\Restore\sitename.bak -Confirm:$false -Verbose -Force
Your mileage may vary, but please post if this works for you.
Cheers!
- Proposed as answer by TGFitch Friday, January 6, 2012 5:57 PM
- Marked as answer by Margriet Bruggeman Monday, April 9, 2012 9:03 AM
Friday, January 6, 2012 5:57 PM
All replies
-
Try backing up to a share instead of a local drive \\localserver\share, and make sure the appropriate sharepoint accounts have full control of the folder and the share. This is the only way you can backup using the GUI, so I would imagine the same applies to a script.Wednesday, March 23, 2011 1:07 PM
-
Steph,
i am using FarmAdministrator user id. i am getting Access denied error on spwebapplication object also. checked local drive security level also.
WebApp.FormDigestSettings.Enabled = false; // Access denied
i can execute bat file in my custom code , which contain Stsadm restore command . but its difficult to pass the parameter to bat file.
Any ideas ??
Wednesday, March 23, 2011 1:22 PM -
Did you find a solution/fix for this? I'm also struggling with this, and it's driving me nuts...!Thursday, December 8, 2011 4:41 PM
-
Ditto. Tried:
1. Confirm the .bak file is NOT Read-Only as suggested elsewhere (it was not, no change required.)
2. Path as a UNC. Same error.
3. Confirmed that the user (Farm Admin) in the SP 2010 Mgt Shell is in Administrator Group on both SP and SQL servers (it was, no change required).
4. CD to directory from within SP 2010 Mgt Shell (no issues).
Note: Running SP 2010 Mgt Shell as my Admin account does not work because it says it doesn't have permissions to the SQL server.
Any help appreciated.
Friday, January 6, 2012 3:51 PM -
Got it - for my situation anyway.
Even though it seems counter-intuitive, I logged into the server as the Farm Admin and opened the Mgt Shell as "Administrator."
for reference the exact command (sanitized) was
restore-spsite -identity http://server/sitename -path c:\Restore\sitename.bak -Confirm:$false -Verbose -Force
Your mileage may vary, but please post if this works for you.
Cheers!
- Proposed as answer by TGFitch Friday, January 6, 2012 5:57 PM
- Marked as answer by Margriet Bruggeman Monday, April 9, 2012 9:03 AM
Friday, January 6, 2012 5:57 PM -
Remember that runwithelevatedprivileges causes the code to run/impersonate as the app pool, but SharePoint sometimes "forgets" about who is running what, so it's best to make sure you have your bases covered.
For your account running the application, make sure you've run the Add-SPShellAdmin for it, as this seems to set some nice permissions that don't always get set.
If it still doesn't work, run the Add-SPShellAdmin for the application pool of the site you are trying to restore.
Friday, January 6, 2012 6:58 PM