Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Pragmatically Backup and restore a site collection

$
0
0

Hi,I'm going to restore a site collection pragmatical. So when user click the CreateNewClient button, It should restore a new site collection named Site1. ( this site collection doesn't exist)

Here is the code:

#region CreateNewClient3
        protected void CreateNewClient3_Click(object sender, EventArgs e)
        {
            try
            {
                string sitecollectionURL = "http://ad/sites/site1";
                string backupfilename = @"E:\\Clientn.bak";
                SPWebApplication parentWebApp;

                using (SPSite siteCol = new SPSite(sitecollectionURL))
                {
                    parentWebApp = siteCol.WebApplication;
                }

                parentWebApp.Sites.Restore(sitecollectionURL, backupfilename, true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion 

and for backup:

#region Backup  
        protected void Backup_Click(object sender, EventArgs e)
        {
            try
            {
                string sitecollectionURL = "http://ad/sites/ClientTest";
                string backupfilename = @"E:\\Clientn.bak";
                SPWebApplication parentWebApp;

                using (SPSite siteCol = new SPSite(sitecollectionURL))
                {
                    parentWebApp = siteCol.WebApplication;
                }

                parentWebApp.Sites.Backup(sitecollectionURL, backupfilename, true);   
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            
            
        }
        #endregion

Backup is working fine but Restore button doesn't work and I get the following error:

The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

I login with administrator (Full permission) and    I've checked web.config :   trust level="Full"

<trust level="Full" originUrl="" legacyCasModel="true" />
    <webParts>

but I still get Access denied 

Could you please advise me?

Thanks



Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>