コード例 #1
0
 /// <summary>
 /// Creates a Template file (.cmp file) based on the specified web site.
 /// File is stored in the specified location.
 /// </summary>
 /// <param name="spWeb"></param>
 /// <param name="pathForTemplateFile"></param>
 public static void exportSpWeb(SPWeb spWeb, string pathForTemplateFile)
 {
     try
     {
         SPExportObject spExportObject = new SPExportObject();
         spExportObject.Id = spWeb.ID;
         spExportObject.IncludeDescendants = SPIncludeDescendants.All;
         spExportObject.Type = SPDeploymentObjectType.Web;
         SPExportSettings exportSettings = new SPExportSettings();
         exportSettings.SiteUrl                   = spWeb.Url;
         exportSettings.ExportMethod              = SPExportMethodType.ExportAll;
         exportSettings.FileLocation              = Path.GetDirectoryName(pathForTemplateFile);
         exportSettings.BaseFileName              = Path.GetFileNameWithoutExtension(pathForTemplateFile);
         exportSettings.FileCompression           = true;
         exportSettings.IncludeSecurity           = SPIncludeSecurity.All;
         exportSettings.ExcludeDependencies       = true;
         exportSettings.OverwriteExistingDataFile = true;
         exportSettings.ExportObjects.Add(spExportObject);
         SPExport export = new SPExport(exportSettings);
         export.Run();
     }
     catch (Exception ex)
     {
         log.addError("Fatal Error: Could not export specified site. " + ex.ToString());
         throw;
     }
 }
コード例 #2
0
ファイル: SiteMenuStrip.cs プロジェクト: keutmann/SPM
        private void BackupMenuItem_Click(object sender, EventArgs e)
        {
            //SaveFileDialog fileDialog = new SaveFileDialog();

            //DialogResult result = fileDialog.ShowDialog();
            //if (result == DialogResult.OK)
            //{
            Cursor.Current = Cursors.WaitCursor;

            SPSite           site       = CurrentNode.Tag as SPSite;
            SPSiteCollection collection = CurrentNode.SPParent as SPSiteCollection;

            string siteurl = site.Url;

            SPExportSettings exportSettings = new SPExportSettings();

            exportSettings.SiteUrl = site.Url;
            Guid           id  = new Guid("d151035f-a876-4d34-8f58-7b6cfdd3ace3");
            SPExportObject edf = new SPExportObject();

            edf.Id = id;
            edf.IncludeDescendants = SPIncludeDescendants.All;
            edf.Type            = SPDeploymentObjectType.File;
            edf.ExcludeChildren = false;

            //exportSettings.ExportMethod = SPExportMethodType.ExportAll;

            exportSettings.BaseFileName    = "MyFile";
            exportSettings.FileLocation    = @"c:\test\";
            exportSettings.FileCompression = true;
            exportSettings.ExportObjects.Add(edf);

            SPExport export = new SPExport(exportSettings);

            export.Run();


            SPImportSettings importSettings = new SPImportSettings();

            importSettings.SiteUrl         = siteurl;
            importSettings.BaseFileName    = "MyFile";
            importSettings.FileLocation    = @"c:\test\";
            importSettings.FileCompression = true;
            importSettings.WebUrl          = siteurl + "/PublishingImages/";

            //SPImportObject imp = new SPImportObject();
            //imp.Type = SPDeploymentObjectType.File;
            //imp.

            SPImport import = new SPImport();

            import.Run();


            //collection.Backup(site.Url, fileDialog.FileName, true);

            Cursor.Current = Cursors.Default;
//            }
        }
コード例 #3
0
        public SPExportSettingsInstance(ObjectInstance prototype)
            : base(prototype)
        {
            m_exportSettings = new SPExportSettings();

            this.PopulateFields();
            this.PopulateFunctions();
        }
        protected void btnCopy_Click(object sender, EventArgs e)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate
            {

                using (SPWeb sourceWeb = new SPSite(SPContext.Current.Web.Url).OpenWeb())
                {
                    SPExportSettings settings = new SPExportSettings();
                    settings.SiteUrl = sourceWeb.Site.Url;
                    settings.ExportMethod = SPExportMethodType.ExportAll;
                    settings.FileLocation = ContentCopierWebPart.ExportLocation;
                    settings.FileCompression = false;
                    settings.CommandLineVerbose = true;
                    settings.OverwriteExistingDataFile = true;

                    foreach (SPList item in sourceWeb.Lists)
                    {
                        SPExportObject exportObject = new SPExportObject();
                        exportObject.Id = item.ID;
                        exportObject.Type = SPDeploymentObjectType.List;
                        settings.ExportObjects.Add(exportObject);
                    }

                    SPExport export = new SPExport(settings);

                     export.Run();

                }

            });

               SPSecurity.RunWithElevatedPrivileges(delegate
                {

                    SPWeb destinationWeb = new SPSite(lstJobs.SelectedItem.Value).OpenWeb();

                        HttpContext.Current.Items["FormDigestValidated"] = "false";
                        destinationWeb.AllowUnsafeUpdates = true;

                        SPImportSettings settings = new SPImportSettings();
                        settings.SiteUrl = destinationWeb.Site.Url;
                        settings.WebUrl = lstJobs.SelectedItem.Value;
                        settings.FileLocation = ContentCopierWebPart.ExportLocation;
                        settings.FileCompression = false;
                        settings.RetainObjectIdentity = false;
                        settings.LogFilePath = ContentCopierWebPart.ExportLocation + @"\export_log.txt";
                        settings.IgnoreWebParts = true;

                        SPImport import = new SPImport(settings);

                        import.Run();
                        HttpContext.Current.Items["FormDigestValidated"] = "false";
                        destinationWeb.AllowUnsafeUpdates = false;

                        Response.Redirect(destinationWeb.Url);

            });
        }
コード例 #5
0
        public SPExportSettingsInstance(ObjectInstance prototype, SPExportSettings exportSettings)
            : this(prototype)
        {
            if (exportSettings == null)
            {
                throw new ArgumentNullException("exportSettings");
            }

            m_exportSettings = exportSettings;
        }
コード例 #6
0
        /// <summary>
        /// Sets up the export objects.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="cabSize">Size of the CAB.</param>
        /// <param name="compressFile">if set to <c>true</c> [compress file].</param>
        /// <param name="filename">The filename.</param>
        /// <param name="haltOnFatalError">if set to <c>true</c> [halt on fatal error].</param>
        /// <param name="haltOnWarning">if set to <c>true</c> [halt on warning].</param>
        /// <param name="includeUserSecurity">if set to <c>true</c> [include user security].</param>
        /// <param name="logFile">if set to <c>true</c> [log file].</param>
        /// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
        /// <param name="quiet">if set to <c>true</c> [quiet].</param>
        /// <param name="versions">The versions.</param>
        internal static void SetupExportObjects(SPExportSettings settings, int cabSize, bool compressFile, string filename, bool haltOnFatalError, bool haltOnWarning, bool includeUserSecurity, bool logFile, bool overwrite, bool quiet, SPIncludeVersions versions)
        {
            if (compressFile)
            {
                new SPDirectoryExistsAndValidFileNameValidator().Validate(filename);
            }
            if (!overwrite && File.Exists(filename))
            {
                throw new SPException(SPResource.GetString("NotOverwriteExportError", new object[] { filename }));
            }

            settings.ExportMethod              = SPExportMethodType.ExportAll;
            settings.HaltOnNonfatalError       = haltOnFatalError;
            settings.HaltOnWarning             = haltOnWarning;
            settings.CommandLineVerbose        = !quiet;
            settings.IncludeVersions           = versions;
            settings.IncludeSecurity           = includeUserSecurity ? SPIncludeSecurity.All : SPIncludeSecurity.None;
            settings.OverwriteExistingDataFile = overwrite;
            settings.FileMaxSize     = cabSize;
            settings.FileCompression = compressFile;

            settings.FileLocation = filename;
            if (!compressFile)
            {
                settings.FileLocation = filename;
            }
            else
            {
                string fileLocation;
                Utilities.SplitPathFile(filename, out fileLocation, out filename);
                settings.FileLocation = fileLocation;
                settings.BaseFileName = filename;
            }

            if (logFile)
            {
                if (!compressFile)
                {
                    settings.LogFilePath = Path.Combine(settings.FileLocation, "export.log");
                }
                else
                {
                    settings.LogFilePath = Path.Combine(settings.FileLocation, filename + ".export.log");
                }
                bool fileExists = File.Exists(settings.LogFilePath);
                if (!overwrite && fileExists)
                {
                    throw new SPException(SPResource.GetString("DataFileExists", new object[] { settings.LogFilePath }));
                }
                if (fileExists)
                {
                    File.Delete(settings.LogFilePath);
                }
            }
        }
コード例 #7
0
ファイル: ExportManager.cs プロジェクト: Fabiarm/spsmovement
 private ExportManager(string siteUrl)
 {
     if (string.IsNullOrEmpty(siteUrl)) throw new Exception("SiteUrl is missing");
     settings = new SPExportSettings();
     settings.SiteUrl = siteUrl;
     settings.AutoGenerateDataFileName = true;
     settings.FileCompression = true;
     settings.ExportPublicSchema = true;
     settings.IncludeSecurity = SPIncludeSecurity.All;
     settings.IncludeVersions = SPIncludeVersions.All;
     settings.ExportMethod = SPExportMethodType.ExportAll;
 }
コード例 #8
0
        private static void storeLargestScopedObject(SPExportSettings ExportSettings)
        {
            List <SPObjectData> objects = new List <SPObjectData>();

            foreach (SPExportObject exportObject in ExportSettings.ExportObjects)
            {
                objects.Add(new SPObjectData(exportObject.Id, exportObject.Url, exportObject.Url, exportObject.Type,
                                             exportObject.IncludeDescendants));
            }

            storeLargestScopedObject(objects);
        }
コード例 #9
0
ファイル: SiteMenuStrip.cs プロジェクト: lucaslra/SPM
        private void BackupMenuItem_Click(object sender, EventArgs e)
        {
            //SaveFileDialog fileDialog = new SaveFileDialog();

            //DialogResult result = fileDialog.ShowDialog();
            //if (result == DialogResult.OK)
            //{
                Cursor.Current = Cursors.WaitCursor;

                SPSite site = CurrentNode.Tag as SPSite;
                SPSiteCollection collection = CurrentNode.SPParent as SPSiteCollection;

                string siteurl = site.Url;

                SPExportSettings exportSettings = new SPExportSettings();
                exportSettings.SiteUrl = site.Url;
                Guid id = new Guid("d151035f-a876-4d34-8f58-7b6cfdd3ace3");
                SPExportObject edf = new SPExportObject();
                edf.Id = id;
                edf.IncludeDescendants = SPIncludeDescendants.All;
                edf.Type = SPDeploymentObjectType.File;
                edf.ExcludeChildren = false;

                //exportSettings.ExportMethod = SPExportMethodType.ExportAll;

                exportSettings.BaseFileName = "MyFile";
                exportSettings.FileLocation = @"c:\test\";
                exportSettings.FileCompression = true;
                exportSettings.ExportObjects.Add(edf);

                SPExport export = new SPExport(exportSettings);
                export.Run();

                SPImportSettings importSettings = new SPImportSettings();
                importSettings.SiteUrl = siteurl;
                importSettings.BaseFileName = "MyFile";
                importSettings.FileLocation = @"c:\test\";
                importSettings.FileCompression = true;
                importSettings.WebUrl = siteurl+"/PublishingImages/";

                //SPImportObject imp = new SPImportObject();
                //imp.Type = SPDeploymentObjectType.File;
                //imp.

                SPImport import = new SPImport();
                import.Run();

                //collection.Backup(site.Url, fileDialog.FileName, true);

                Cursor.Current = Cursors.Default;
            //            }
        }
コード例 #10
0
        public static string GetLastToken(SPExportSettings ExportSettings)
        {
            // find the most recent token for the scope of the current export operation..
            string changeToken = string.Empty;

            if (ChangeTokens.Count > 0)
            {
                storeLargestScopedObject(ExportSettings);

                changeToken = ChangeTokens.FindLast(containsScopeID);
            }

            return(changeToken);
        }
コード例 #11
0
        public static string GetLastToken(SPExportSettings ExportSettings)
        {
            // find the most recent token for the scope of the current export operation.. 
            string changeToken = string.Empty;

            if (ChangeTokens.Count > 0)
            {
                storeLargestScopedObject(ExportSettings);

                changeToken = ChangeTokens.FindLast(containsScopeID);
            }

            return changeToken;
        }
コード例 #12
0
        /// <summary>
        /// Performs the export.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="filename">The filename.</param>
        /// <param name="compressFile">if set to <c>true</c> [compress file].</param>
        /// <param name="haltOnFatalError">if set to <c>true</c> [halt on fatal error].</param>
        /// <param name="haltOnWarning">if set to <c>true</c> [halt on warning].</param>
        /// <param name="includeusersecurity">if set to <c>true</c> [includeusersecurity].</param>
        /// <param name="cabSize">Size of the CAB.</param>
        /// <param name="logFile">if set to <c>true</c> [log file].</param>
        /// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
        /// <param name="quiet">if set to <c>true</c> [quiet].</param>
        /// <param name="versions">The versions.</param>
        /// <param name="includeDescendents">The include descendents.</param>
        /// <param name="excludeDependencies">if set to <c>true</c> [exclude dependencies].</param>
        public static void PerformExport(string url, string filename, bool compressFile, bool haltOnFatalError, bool haltOnWarning, bool includeusersecurity, int cabSize, bool logFile, bool overwrite, bool quiet, SPIncludeVersions versions, SPIncludeDescendants includeDescendents, bool excludeDependencies, bool useSqlSnapshot, bool excludeChildren)
        {
            SPExportObject exportObject = new SPExportObject();
            SPExportSettings settings = new SPExportSettings();
            settings.ExcludeDependencies = excludeDependencies;
            SPExport export = new SPExport(settings);

            exportObject.Type = SPDeploymentObjectType.List;
            exportObject.IncludeDescendants = includeDescendents;
            exportObject.ExcludeChildren = excludeChildren;
            StsAdm.OperationHelpers.ExportHelper.SetupExportObjects(settings, cabSize, compressFile, filename, haltOnFatalError, haltOnWarning, includeusersecurity, logFile, overwrite, quiet, versions);

            PerformExport(export, exportObject, settings, logFile, quiet, url, useSqlSnapshot);
        }
コード例 #13
0
        public bool Export(SPWeb web, string filename)
        {
            SPExportSettings exportSettings = new SPExportSettings();

            exportSettings.SiteUrl      = web.Url;
            exportSettings.ExportMethod = SPExportMethodType.ExportAll;
            exportSettings.BaseFileName = Helper.Instance.ExtractFileName(filename);
            exportSettings.FileLocation = Helper.Instance.ExtractFolder(filename);
            exportSettings.OverwriteExistingDataFile = true;

            SPExport export = new SPExport(exportSettings);

            export.Run();

            return(true);
        }
コード例 #14
0
        /// <summary>
        /// Performs the export.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="filename">The filename.</param>
        /// <param name="compressFile">if set to <c>true</c> [compress file].</param>
        /// <param name="haltOnFatalError">if set to <c>true</c> [halt on fatal error].</param>
        /// <param name="haltOnWarning">if set to <c>true</c> [halt on warning].</param>
        /// <param name="includeusersecurity">if set to <c>true</c> [includeusersecurity].</param>
        /// <param name="cabSize">Size of the CAB.</param>
        /// <param name="logFile">if set to <c>true</c> [log file].</param>
        /// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
        /// <param name="quiet">if set to <c>true</c> [quiet].</param>
        /// <param name="versions">The versions.</param>
        /// <param name="includeDescendents">The include descendents.</param>
        /// <param name="excludeDependencies">if set to <c>true</c> [exclude dependencies].</param>
        public static void PerformExport(string url, string filename, bool compressFile, bool haltOnFatalError, bool haltOnWarning, bool includeusersecurity, int cabSize, bool logFile, bool overwrite, bool quiet, SPIncludeVersions versions, SPIncludeDescendants includeDescendents, bool excludeDependencies, bool useSqlSnapshot, bool excludeChildren)
        {
            SPExportObject   exportObject = new SPExportObject();
            SPExportSettings settings     = new SPExportSettings();

            settings.ExcludeDependencies = excludeDependencies;
            SPExport export = new SPExport(settings);


            exportObject.Type = SPDeploymentObjectType.List;
            exportObject.IncludeDescendants = includeDescendents;
            exportObject.ExcludeChildren    = excludeChildren;
            StsAdm.OperationHelpers.ExportHelper.SetupExportObjects(settings, cabSize, compressFile, filename, haltOnFatalError, haltOnWarning, includeusersecurity, logFile, overwrite, quiet, versions);



            PerformExport(export, exportObject, settings, logFile, quiet, url, useSqlSnapshot);
        }
コード例 #15
0
        protected void exportButton_Click(object sender, EventArgs e)
        {
            //Create an export settings object to configure the export
            SPExportSettings exportSettings = new SPExportSettings();

            //Set the site you want to export from. Alter this to match your site.
            exportSettings.SiteUrl = "http://intranet.contoso.com";
            //Select a full export (alternatively you could do an incremental export to just include changes)
            exportSettings.ExportMethod = SPExportMethodType.ExportAll;
            //Set the location and name of the export file
            exportSettings.BaseFileName = "demoTasksExport";
            exportSettings.FileLocation = @"C:\";

            //To export just the Tasks list, first create an ExportObject
            SPExportObject tasksEO = new SPExportObject();

            //We must set it to export a SharePoint List
            tasksEO.Type = SPDeploymentObjectType.List;
            //We want to export everything in the list
            tasksEO.IncludeDescendants = SPIncludeDescendants.All;
            //Set the URL of the list to export.
            tasksEO.Url = "http://intranet.contoso.com/lists/tasks";
            //Add that to the Export Objects collection
            exportSettings.ExportObjects.Add(tasksEO);

            //Do the export
            SPExport export = new SPExport(exportSettings);

            try
            {
                export.Run();
                resultsLabel.Text = "The export ran successfully";
            }
            catch (Exception ex)
            {
                resultsLabel.Text = "The export generated an error: " + ex.Message;
            }
        }
コード例 #16
0
        protected override void InternalProcessRecord()
        {
            bool createLogFile = !base.NoLogFile.IsPresent;

            if (!base.NoFileCompression.IsPresent)
            {
                this.ValidateDirectory(base.Path);
            }
            if ((!base.Force.IsPresent) && File.Exists(base.Path))
            {
                throw new SPException(string.Format("PSCannotOverwriteExport,{0}", base.Path));
            }
            SPExportSettings settings = new SPExportSettings();
            SPExport         export   = new SPExport(settings);

            base.SetDeploymentSettings(settings);
            settings.ExportMethod        = SPExportMethodType.ExportAll;
            settings.ExcludeDependencies = !IncludeDependencies.IsPresent;
            SPDatabaseSnapshot snapshot = null;

            if (!this.UseSqlSnapshot.IsPresent)
            {
                settings.SiteUrl = this.SiteUrl;
            }
            else
            {
                snapshot = this.Site.ContentDatabase.Snapshots.CreateSnapshot();
                SPContentDatabase database2 = SPContentDatabase.CreateUnattachedContentDatabase(snapshot.ConnectionString);
                settings.UnattachedContentDatabase = database2;
                settings.SiteUrl = database2.Sites[this.Site.ServerRelativeUrl].Url;
            }
            SPExportObject exportObject = this.ExportObject;

            if (((exportObject.Type != SPDeploymentObjectType.Web) ||
                 base.ShouldProcess(string.Format("ShouldProcessExportWeb,{0},{1}", this.SiteUrl, base.Path))) &&
                ((exportObject.Type != SPDeploymentObjectType.List) ||
                 base.ShouldProcess(string.Format("ShouldProcessExportList,{0},{1}", this.SiteUrl + "/" + this.ItemUrl, base.Path))))
            {
                if (exportObject != null)
                {
                    exportObject.ExcludeChildren    = ExcludeChildren.IsPresent;
                    exportObject.IncludeDescendants = IncludeDescendants;
                    settings.ExportObjects.Add(exportObject);
                }
                settings.IncludeVersions = this.IncludeVersions;
                if (base.IncludeUserSecurity.IsPresent)
                {
                    settings.IncludeSecurity = SPIncludeSecurity.All;
                }
                settings.OverwriteExistingDataFile = (bool)base.Force;
                settings.FileMaxSize = this.CompressionSize;
                try
                {
                    export.Run();
                }
                finally
                {
                    if (base.Verbose && createLogFile)
                    {
                        Console.WriteLine();
                        Console.WriteLine(SPResource.GetString("ExportOperationLogFile", new object[0]));
                        Console.WriteLine("\t{0}", settings.LogFilePath);
                    }
                    if ((this.UseSqlSnapshot.IsPresent) && (snapshot != null))
                    {
                        snapshot.Delete();
                    }
                }
                if (base.Verbose)
                {
                    string    fileLocation = settings.FileLocation;
                    ArrayList dataFiles    = settings.DataFiles;
                    if (dataFiles != null)
                    {
                        if (((fileLocation != null) && (fileLocation.Length > 0)) && (fileLocation[fileLocation.Length - 1] != System.IO.Path.DirectorySeparatorChar))
                        {
                            fileLocation = fileLocation + System.IO.Path.DirectorySeparatorChar;
                        }
                        Console.WriteLine();
                        Console.WriteLine(SPResource.GetString("ExportOperationFilesGenerated", new object[0]));
                        for (int i = 0; i < dataFiles.Count; i++)
                        {
                            Console.WriteLine("\t{0}{1}", fileLocation, dataFiles[i]);
                            Console.WriteLine();
                        }
                        if (base.NoFileCompression.IsPresent)
                        {
                            DirectoryInfo info = new DirectoryInfo(base.Path);
                            Console.WriteLine("\t{0}", info.FullName);
                        }
                        Console.WriteLine();
                    }
                }
            }
        }
コード例 #17
0
 protected override void InternalProcessRecord()
 {
     bool createLogFile = !base.NoLogFile.IsPresent;
     if (!base.NoFileCompression.IsPresent)
     {
         this.ValidateDirectory(base.Path);
     }
     if ((!base.Force.IsPresent) && File.Exists(base.Path))
     {
         throw new SPException(string.Format("PSCannotOverwriteExport,{0}", base.Path));
     }
     SPExportSettings settings = new SPExportSettings();
     SPExport export = new SPExport(settings);
     base.SetDeploymentSettings(settings);
     settings.ExportMethod = SPExportMethodType.ExportAll;
     settings.ExcludeDependencies = !IncludeDependencies.IsPresent;
     SPDatabaseSnapshot snapshot = null;
     if (!this.UseSqlSnapshot.IsPresent)
     {
         settings.SiteUrl = this.SiteUrl;
     }
     else
     {
         snapshot = this.Site.ContentDatabase.Snapshots.CreateSnapshot();
         SPContentDatabase database2 = SPContentDatabase.CreateUnattachedContentDatabase(snapshot.ConnectionString);
         settings.UnattachedContentDatabase = database2;
         settings.SiteUrl = database2.Sites[this.Site.ServerRelativeUrl].Url;
     }
     SPExportObject exportObject = this.ExportObject;
     if (((exportObject.Type != SPDeploymentObjectType.Web) ||
         base.ShouldProcess(string.Format("ShouldProcessExportWeb,{0},{1}", this.SiteUrl, base.Path ))) &&
         ((exportObject.Type != SPDeploymentObjectType.List) ||
         base.ShouldProcess(string.Format("ShouldProcessExportList,{0},{1}", this.SiteUrl + "/" + this.ItemUrl, base.Path))))
     {
         if (exportObject != null)
         {
             exportObject.ExcludeChildren = ExcludeChildren.IsPresent;
             exportObject.IncludeDescendants = IncludeDescendants;
             settings.ExportObjects.Add(exportObject);
         }
         settings.IncludeVersions = this.IncludeVersions;
         if (base.IncludeUserSecurity.IsPresent)
         {
             settings.IncludeSecurity = SPIncludeSecurity.All;
         }
         settings.OverwriteExistingDataFile = (bool)base.Force;
         settings.FileMaxSize = this.CompressionSize;
         try
         {
             export.Run();
         }
         finally
         {
             if (base.Verbose && createLogFile)
             {
                 Console.WriteLine();
                 Console.WriteLine(SPResource.GetString("ExportOperationLogFile", new object[0]));
                 Console.WriteLine("\t{0}", settings.LogFilePath);
             }
             if ((this.UseSqlSnapshot.IsPresent) && (snapshot != null))
             {
                 snapshot.Delete();
             }
         }
         if (base.Verbose)
         {
             string fileLocation = settings.FileLocation;
             ArrayList dataFiles = settings.DataFiles;
             if (dataFiles != null)
             {
                 if (((fileLocation != null) && (fileLocation.Length > 0)) && (fileLocation[fileLocation.Length - 1] != System.IO.Path.DirectorySeparatorChar))
                 {
                     fileLocation = fileLocation + System.IO.Path.DirectorySeparatorChar;
                 }
                 Console.WriteLine();
                 Console.WriteLine(SPResource.GetString("ExportOperationFilesGenerated", new object[0]));
                 for (int i = 0; i < dataFiles.Count; i++)
                 {
                     Console.WriteLine("\t{0}{1}", fileLocation, dataFiles[i]);
                     Console.WriteLine();
                 }
                 if (base.NoFileCompression.IsPresent)
                 {
                     DirectoryInfo info = new DirectoryInfo(base.Path);
                     Console.WriteLine("\t{0}", info.FullName);
                 }
                 Console.WriteLine();
             }
         }
     }
 }
        protected void btnMove_Click(object sender, EventArgs e)
        {
            if (ThisWebPart.DestionationSiteCollectionUrl != null)
            {

                oSite = new SPSite(ThisWebPart.DestionationSiteCollectionUrl + "/jobs/" + DateTime.Now.Year);

                SPSecurity.RunWithElevatedPrivileges(delegate
                {

                    using (SPWeb sourceWeb = new SPSite(SPContext.Current.Web.Url).OpenWeb())
                    {
                        SPExportSettings settings = new SPExportSettings();
                        settings.SiteUrl = sourceWeb.Site.Url;
                        settings.ExportMethod = SPExportMethodType.ExportAll;
                        settings.FileLocation = ThisWebPart.ExportLocation;
                        settings.FileCompression = false;
                        settings.CommandLineVerbose = true;
                        settings.OverwriteExistingDataFile = true;

                        foreach (SPList item in sourceWeb.Lists)
                        {
                            SPExportObject exportObject = new SPExportObject();
                            exportObject.Id = item.ID;
                            exportObject.Type = SPDeploymentObjectType.List;
                            settings.ExportObjects.Add(exportObject);
                        }

                        SPExport export = new SPExport(settings);

                        export.Run();

                    }

                });

                SPWeb destinationWeb = new SPSite(lstJobs.SelectedItem.Value).OpenWeb();

                SPSecurity.RunWithElevatedPrivileges(delegate
                {

                    HttpContext.Current.Items["FormDigestValidated"] = "false";
                    destinationWeb.AllowUnsafeUpdates = true;

                    SPImportSettings settings = new SPImportSettings();
                    settings.SiteUrl = destinationWeb.Site.Url;
                    settings.WebUrl = lstJobs.SelectedItem.Value;
                    settings.FileLocation = ThisWebPart.ExportLocation;
                    settings.FileCompression = false;
                    settings.RetainObjectIdentity = false;
                    settings.LogFilePath = ThisWebPart.ExportLocation + @"\export_log.txt";
                    settings.IgnoreWebParts = true;

                    SPImport import = new SPImport(settings);

                    import.Run();
                    HttpContext.Current.Items["FormDigestValidated"] = "false";
                    destinationWeb.AllowUnsafeUpdates = false;

                });

                var currentUser = Request.LogonUserIdentity.ToString();

                SPSecurity.RunWithElevatedPrivileges(delegate
                {

                    SPWeb sourceWeb = new SPSite(SPContext.Current.Web.Url).OpenWeb();

                    SPWeb blueberryWeb = sourceWeb.Site.AllWebs["Blueberry"];
                    SPList proposalList = blueberryWeb.Lists["Proposals"];
                    var proposalRecordID = int.Parse(sourceWeb.Properties["ProposalRecordID"].ToString());

                    SPListItem proposalRecord = proposalList.GetItemById(proposalRecordID);
                    proposalRecord["JobNumber"] = lstJobs.SelectedItem.Text;
                    proposalRecord["BecameJobOn"] = DateTime.Now;
                    proposalRecord.Update();

                    sourceWeb.AllowUnsafeUpdates = true;

                    sourceWeb.Delete();

                });

                Response.Redirect(destinationWeb.Url);
            }
        }
コード例 #19
0
        /// <summary>
        /// Performs the export.
        /// </summary>
        /// <param name="export">The export.</param>
        /// <param name="exportObject">The export object.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="logFile">if set to <c>true</c> [log file].</param>
        /// <param name="quiet">if set to <c>true</c> [quiet].</param>
        /// <param name="url">The URL.</param>
        internal static void PerformExport(SPExport export, SPExportObject exportObject, SPExportSettings settings, bool logFile, bool quiet, string url, bool useSqlSnapshot)
        {
            SPDatabaseSnapshot snapshot = null;

            using (SPSite site = new SPSite(url))
            {
                ValidateUser(site);

                if (!useSqlSnapshot)
                {
                    settings.SiteUrl = site.Url;
                }
                else
                {
                    snapshot = site.ContentDatabase.Snapshots.CreateSnapshot();
                    SPContentDatabase database2 = SPContentDatabase.CreateUnattachedContentDatabase(snapshot.ConnectionString);
                    settings.UnattachedContentDatabase = database2;
                    settings.SiteUrl = database2.Sites[site.ServerRelativeUrl].Url;
                }

                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = Utilities.GetListFromViewUrl(web, url);

                    if (list == null)
                    {
                        throw new Exception("List not found.");
                    }

                    settings.SiteUrl = web.Url;
                    exportObject.Id  = list.ID;
                }

                settings.ExportObjects.Add(exportObject);


                try
                {
                    export.Run();
                    if (!quiet)
                    {
                        ArrayList dataFiles = settings.DataFiles;
                        if (dataFiles != null)
                        {
                            Console.WriteLine();
                            Console.WriteLine("File(s) generated: ");
                            for (int i = 0; i < dataFiles.Count; i++)
                            {
                                Console.WriteLine("\t{0}", Path.Combine(settings.FileLocation, (string)dataFiles[i]));
                                Console.WriteLine();
                            }
                            Console.WriteLine();
                        }
                    }
                }
                finally
                {
                    if (useSqlSnapshot && (snapshot != null))
                    {
                        snapshot.Delete();
                    }

                    if (logFile)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Log file generated: ");
                        Console.WriteLine("\t{0}", settings.LogFilePath);
                    }
                }
            }
        }
コード例 #20
0
        private ArrayInstance ExportInternal(object fileLocation, object baseFileName, object logFilePath, IEnumerable <SPExportObject> exportObjects, object dropLocation)
        {
            var exportSettings = new SPExportSettings
            {
                ExportMethod              = Microsoft.SharePoint.Deployment.SPExportMethodType.ExportAll,
                SiteUrl                   = SPBaristaContext.Current.Site.Url,
                IncludeSecurity           = Microsoft.SharePoint.Deployment.SPIncludeSecurity.All,
                IncludeVersions           = Microsoft.SharePoint.Deployment.SPIncludeVersions.All,
                OverwriteExistingDataFile = true
            };

            if (fileLocation != Null.Value && fileLocation != Undefined.Value)
            {
                var strFileLocation = TypeConverter.ToString(fileLocation);
                if (strFileLocation.IsNullOrWhiteSpace() == false)
                {
                    exportSettings.AutoGenerateDataFileName = false;
                    exportSettings.FileLocation             = strFileLocation;
                }
            }

            if (baseFileName != Null.Value && baseFileName != Undefined.Value)
            {
                var strBaseFileName = TypeConverter.ToString(baseFileName);
                if (strBaseFileName.IsNullOrWhiteSpace() == false)
                {
                    exportSettings.AutoGenerateDataFileName = false;
                    exportSettings.BaseFileName             = strBaseFileName;
                }
            }

            if (logFilePath != Null.Value && logFilePath != Undefined.Value)
            {
                var strLogFilePath = TypeConverter.ToString(logFilePath);
                if (strLogFilePath.IsNullOrWhiteSpace() == false)
                {
                    exportSettings.LogFilePath = strLogFilePath;
                }
            }

            foreach (var obj in exportObjects)
            {
                exportSettings.ExportObjects.Add(obj);
            }

            var export = new SPExport(exportSettings);

            export.Run();

            if (dropLocation != Null.Value && dropLocation != Undefined.Value)
            {
                SPExportInstance.CopyFilesToDropLocation(export, TypeConverter.ToString(dropLocation));
            }

            var result = Engine.Array.Construct();

            foreach (var dataFile in exportSettings.DataFiles.OfType <string>())
            {
                ArrayInstance.Push(result, Path.Combine(exportSettings.FileLocation, dataFile));
            }
            return(result);
        }
コード例 #21
0
 public WizardExportSettings(SPExportSettings ExportSettings, List <SPObjectData> MappedObjects)
 {
     Settings          = ExportSettings;
     SupplementaryData = MappedObjects;
 }
コード例 #22
0
 public WizardExportSettings(SPExportSettings ExportSettings, List<SPObjectData> MappedObjects)
 {
     Settings = ExportSettings;
     SupplementaryData = MappedObjects;
 }
コード例 #23
0
        /// <summary>
        /// Sets up the export objects.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="cabSize">Size of the CAB.</param>
        /// <param name="compressFile">if set to <c>true</c> [compress file].</param>
        /// <param name="filename">The filename.</param>
        /// <param name="haltOnFatalError">if set to <c>true</c> [halt on fatal error].</param>
        /// <param name="haltOnWarning">if set to <c>true</c> [halt on warning].</param>
        /// <param name="includeUserSecurity">if set to <c>true</c> [include user security].</param>
        /// <param name="logFile">if set to <c>true</c> [log file].</param>
        /// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
        /// <param name="quiet">if set to <c>true</c> [quiet].</param>
        /// <param name="versions">The versions.</param>
        internal static void SetupExportObjects(SPExportSettings settings, int cabSize, bool compressFile, string filename, bool haltOnFatalError, bool haltOnWarning, bool includeUserSecurity, bool logFile, bool overwrite, bool quiet, SPIncludeVersions versions)
        {
            if (compressFile)
            {
                new SPDirectoryExistsAndValidFileNameValidator().Validate(filename);
            }
            if (!overwrite && File.Exists(filename))
                throw new SPException(SPResource.GetString("NotOverwriteExportError", new object[] { filename }));

            settings.ExportMethod = SPExportMethodType.ExportAll;
            settings.HaltOnNonfatalError = haltOnFatalError;
            settings.HaltOnWarning = haltOnWarning;
            settings.CommandLineVerbose = !quiet;
            settings.IncludeVersions = versions;
            settings.IncludeSecurity = includeUserSecurity ? SPIncludeSecurity.All : SPIncludeSecurity.None;
            settings.OverwriteExistingDataFile = overwrite;
            settings.FileMaxSize = cabSize;
            settings.FileCompression = compressFile;

            settings.FileLocation = filename;
            if (!compressFile)
            {
                settings.FileLocation = filename;
            }
            else
            {
                string fileLocation;
                Utilities.SplitPathFile(filename, out fileLocation, out filename);
                settings.FileLocation = fileLocation;
                settings.BaseFileName = filename;
            }

            if (logFile)
            {
                if (!compressFile)
                {
                    settings.LogFilePath = Path.Combine(settings.FileLocation, "export.log");
                }
                else
                {
                    settings.LogFilePath = Path.Combine(settings.FileLocation, filename + ".export.log");
                }
                bool fileExists = File.Exists(settings.LogFilePath);
                if (!overwrite && fileExists)
                {
                    throw new SPException(SPResource.GetString("DataFileExists", new object[] { settings.LogFilePath }));
                }
                if (fileExists)
                {
                    File.Delete(settings.LogFilePath);
                }
            }
        }
コード例 #24
0
        void wizardControl1_NextButtonClick(WizardBase.WizardControl sender, WizardBase.WizardNextButtonClickEventArgs args)
        {
            switch (wizardControl1.CurrentStepIndex)
            {
                case f_ciSITE_DETAILS_STEP_INDEX:
                    Cursor = Cursors.WaitCursor;
                    if (validateUserParams(f_ciSITE_DETAILS_STEP_INDEX))
                    {
                        if (rdoExport.Checked)
                        {
                            f_action = WizardAction.Export;

                            m_bindingMsgForm.Show(this);
                            m_bindingMsgForm.Refresh();

                            // bind treeview..
                            using (SPSite exportSite = new SPSite(f_sSiteUrl))
                            {
                                doSiteTreeBind(exportSite);
                            }

                            OnSiteBindComplete();
                            if (f_exportSettings != null)
                            {
                                addSavedExportItemsToExportListView(f_exportSettings);
                            }
                            args.NextStepIndex = f_ciEXPORT_SELECT_STEP_INDEX;
                        }
                        else
                        {
                            f_action = WizardAction.Import;
                            args.NextStepIndex = f_ciIMPORT_STEP_INDEX;
                        }
                    }
                    else
                    {
                        args.Cancel = true;
                    }
                    Cursor = Cursors.Default;
                    break;
                case f_ciIMPORT_STEP_INDEX:
                    if (validateUserParams(f_ciIMPORT_STEP_INDEX))
                    {
                        args.NextStepIndex = f_ciFINISH_STEP_INDEX;
                    }
                    else
                    {
                        args.Cancel = true;
                    }
                    break;
                case f_ciEXPORT_SELECT_STEP_INDEX:
                    if (validateUserParams(f_ciEXPORT_SELECT_STEP_INDEX))
                    {
                        args.NextStepIndex = f_ciEXPORT_SETTINGS_STEP_INDEX;
                    }
                    else
                    {
                        args.Cancel = true;
                    }
                    break;
                case f_ciEXPORT_SETTINGS_STEP_INDEX:
                    // clear down saved settings from file in case user uses back button..
                    f_exportSettings = null;
                    if (validateUserParams(f_ciEXPORT_SETTINGS_STEP_INDEX))
                    {
                        args.NextStepIndex = f_ciFINISH_STEP_INDEX;
                    }
                    else
                    {
                        args.Cancel = true;
                    }
                    break;
                default:
                    break;
            }
        }
コード例 #25
0
        /// <summary>
        /// Performs the export.
        /// </summary>
        /// <param name="export">The export.</param>
        /// <param name="exportObject">The export object.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="logFile">if set to <c>true</c> [log file].</param>
        /// <param name="quiet">if set to <c>true</c> [quiet].</param>
        /// <param name="url">The URL.</param>
        internal static void PerformExport(SPExport export, SPExportObject exportObject, SPExportSettings settings, bool logFile, bool quiet, string url, bool useSqlSnapshot)
        {
            SPDatabaseSnapshot snapshot = null;
            using (SPSite site = new SPSite(url))
            {
                ValidateUser(site);

                if (!useSqlSnapshot)
                {
                    settings.SiteUrl = site.Url;
                }
                else
                {
                    snapshot = site.ContentDatabase.Snapshots.CreateSnapshot();
                    SPContentDatabase database2 = SPContentDatabase.CreateUnattachedContentDatabase(snapshot.ConnectionString);
                    settings.UnattachedContentDatabase = database2;
                    settings.SiteUrl = database2.Sites[site.ServerRelativeUrl].Url;
                }

                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = Utilities.GetListFromViewUrl(web, url);

                    if (list == null)
                    {
                        throw new Exception("List not found.");
                    }

                    settings.SiteUrl = web.Url;
                    exportObject.Id = list.ID;
                }

                settings.ExportObjects.Add(exportObject);

                try
                {
                    export.Run();
                    if (!quiet)
                    {
                        ArrayList dataFiles = settings.DataFiles;
                        if (dataFiles != null)
                        {
                            Console.WriteLine();
                            Console.WriteLine("File(s) generated: ");
                            for (int i = 0; i < dataFiles.Count; i++)
                            {
                                Console.WriteLine("\t{0}", Path.Combine(settings.FileLocation, (string)dataFiles[i]));
                                Console.WriteLine();
                            }
                            Console.WriteLine();

                        }
                    }
                }
                finally
                {
                    if (useSqlSnapshot && (snapshot != null))
                    {
                        snapshot.Delete();
                    }

                    if (logFile)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Log file generated: ");
                        Console.WriteLine("\t{0}", settings.LogFilePath);
                    }
                }
            }
        }
コード例 #26
0
        private void btnLoadSettings_Click(object sender, EventArgs e)
        {

            if (f_traceSwitch.TraceVerbose)
            {
                f_traceHelper.TraceVerbose("btnLoadSettings_Click: Entered.");
            }

            string sPath = string.Empty;

            if (f_dlgLoadSettingsFile.ShowDialog() == DialogResult.OK)
            {
                sPath = f_dlgLoadSettingsFile.FileName;
                if (f_traceSwitch.TraceInfo)
                {
                    f_traceHelper.TraceInfo("btnLoadLoadingSettings_Click: Loading saved settings from '{0}'.", sPath);
                }

                // determine whether we are loading import or export settings, then get SPImportSettings/SPExportSettings, then set controls..

                Byte[] fileBytes = null;
                XmlTextReader xReader = null;
                using (xReader = new XmlTextReader(sPath))
                {
                    xReader.WhitespaceHandling = WhitespaceHandling.None;
                    xReader.MoveToContent();
                    string sXml = xReader.ReadOuterXml();
                    UTF8Encoding encoding = new UTF8Encoding();
                    fileBytes = encoding.GetBytes(sXml);
                }

                WizardOperationSettings settings = null;
                using (MemoryStream settingsMemStream = new MemoryStream(fileBytes))
                {
                    settingsMemStream.Position = 0;

                    using (xReader = new XmlTextReader(settingsMemStream))
                    {
                        settings = WizardDeployment.CollectSettings(xReader);
                    }
                }

                if (settings != null)
                {
                    if (settings is WizardExportSettings)
                    {
                        WizardExportSettings weSettings = (WizardExportSettings)settings;
                        loadSettings(weSettings);
                        f_exportSettings = (SPExportSettings)settings.Settings;
                        f_supplementaryExportSettings = weSettings;
                    }
                    if (settings is WizardImportSettings)
                    {
                        WizardImportSettings wiSettings = (WizardImportSettings)settings;
                        loadSettings(wiSettings);
                    }
                }
                else
                {
                    MessageBox.Show(
                        "Unable to load settings from this file! XML root node was not of type 'ImportSettings' or 'ExportSettings.",
                        "Error loading settings", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                if (f_traceSwitch.TraceInfo)
                {
                    f_traceHelper.TraceInfo("btnLoadSettings_Click: Not loading file, user cancelled out of dialog.");
                }
            }

            if (f_traceSwitch.TraceVerbose)
            {
                f_traceHelper.TraceVerbose("btnLoadSettings_Click: Leaving.");
            }
        }
コード例 #27
0
        private void addSavedExportItemsToExportListView(SPExportSettings exportSettings)
        {
            lstExportItems.Items.Clear();

            List<SPObjectData> exportObjects = f_supplementaryExportSettings.SupplementaryData;
            foreach (SPObjectData exportObject in exportObjects)
            {
                lstExportItems.Items.Add(getListViewItemFromExportObject(exportObject));
            }
        }
コード例 #28
0
        internal static WizardExportSettings CollectExportSettings(XmlTextReader exportSettingsXml)
        {
            if (traceSwitchStatic.TraceVerbose)
            {
                traceStatic.TraceVerbose("CollectExportSettings: Entered CollectExportSettings().");
            }

            // create SPExportSettings object..
            SPExportSettings    exportSettings      = new SPExportSettings();
            List <SPObjectData> exportObjectDetails = new List <SPObjectData>();

            if (exportSettingsXml.Name != "ExportSettings")
            {
                exportSettingsXml.Read();
            }

            if (exportSettingsXml.Name == "ExportSettings")
            {
                if (exportSettingsXml.MoveToAttribute("SiteUrl"))
                {
                    exportSettings.SiteUrl = exportSettingsXml.Value;
                }
                if (exportSettingsXml.MoveToAttribute("ExcludeDependencies"))
                {
                    exportSettings.ExcludeDependencies = bool.Parse(exportSettingsXml.Value);
                }
                if (exportSettingsXml.MoveToAttribute("ExportMethod"))
                {
                    exportSettings.ExportMethod =
                        (SPExportMethodType)Enum.Parse(typeof(SPExportMethodType), exportSettingsXml.Value);
                }
                if (exportSettingsXml.MoveToAttribute("IncludeVersions"))
                {
                    exportSettings.IncludeVersions =
                        (SPIncludeVersions)Enum.Parse(typeof(SPIncludeVersions), exportSettingsXml.Value);
                }
                if (exportSettingsXml.MoveToAttribute("IncludeSecurity"))
                {
                    exportSettings.IncludeSecurity =
                        (SPIncludeSecurity)Enum.Parse(typeof(SPIncludeSecurity), exportSettingsXml.Value);
                }
                if (exportSettingsXml.MoveToAttribute("FileCompression"))
                {
                    exportSettings.FileCompression = bool.Parse(exportSettingsXml.Value);
                }
                if (exportSettingsXml.MoveToAttribute("FileLocation"))
                {
                    exportSettings.FileLocation = exportSettingsXml.Value;
                }
                if (exportSettingsXml.MoveToAttribute("BaseFileName"))
                {
                    exportSettings.BaseFileName = exportSettingsXml.Value;
                }
                if (exportSettingsXml.MoveToAttribute("IncludeSecurity"))
                {
                    exportSettings.IncludeSecurity =
                        (SPIncludeSecurity)Enum.Parse(typeof(SPIncludeSecurity), exportSettingsXml.Value);
                }

                exportSettingsXml.MoveToElement();
            }

            while (exportSettingsXml.Read())
            {
                if (exportSettingsXml.Name == "DeploymentObject")
                {
                    SPExportObject exportObject     = new SPExportObject();
                    SPObjectData   exportObjectData = new SPObjectData();

                    if (exportSettingsXml.MoveToAttribute("Id"))
                    {
                        Guid gID = new Guid(exportSettingsXml.Value);
                        exportObject.Id     = gID;
                        exportObjectData.ID = gID;
                    }
                    if (exportSettingsXml.MoveToAttribute("Type"))
                    {
                        SPDeploymentObjectType type = (SPDeploymentObjectType)
                                                      Enum.Parse(typeof(SPDeploymentObjectType), exportSettingsXml.Value);
                        exportObject.Type           = type;
                        exportObjectData.ObjectType = type;
                    }
                    if (exportSettingsXml.MoveToAttribute("ExcludeChildren"))
                    {
                        bool bExcludeChildren = bool.Parse(exportSettingsXml.Value);
                        exportObject.ExcludeChildren     = bExcludeChildren;
                        exportObjectData.ExcludeChildren = bExcludeChildren;
                    }
                    if (exportSettingsXml.MoveToAttribute("IncludeDescendants"))
                    {
                        SPIncludeDescendants includeDescs = (SPIncludeDescendants)
                                                            Enum.Parse(typeof(SPIncludeDescendants),
                                                                       exportSettingsXml.Value);
                        exportObject.IncludeDescendants     = includeDescs;
                        exportObjectData.IncludeDescendents = includeDescs;
                    }
                    if (exportSettingsXml.MoveToAttribute("Url"))
                    {
                        exportObject.Url     = exportSettingsXml.Value;
                        exportObjectData.Url = exportSettingsXml.Value;
                    }
                    if (exportSettingsXml.MoveToAttribute("Title"))
                    {
                        exportObjectData.Title = exportSettingsXml.Value;
                    }

                    exportSettings.ExportObjects.Add(exportObject);
                    exportObjectDetails.Add(exportObjectData);
                }
            }

            exportSettingsXml.Close();

            // set other properties which aren't tied to values in XML..
            exportSettings.TestRun = false;
            exportSettings.OverwriteExistingDataFile = true;
            exportSettings.LogFilePath = string.Format("{0}\\{1}.Export.log",
                                                       exportSettings.FileLocation, exportSettings.BaseFileName);

            if (traceSwitchStatic.TraceInfo)
            {
                traceStatic.TraceInfo("CollectExportSettings: Using site URL '{0}'.", exportSettings.SiteUrl);
                traceStatic.TraceInfo("CollectExportSettings: Exclude dependencies IDs = '{0}'.", exportSettings.ExcludeDependencies);
                traceStatic.TraceInfo("CollectExportSettings: Export method = '{0}'.", exportSettings.ExportMethod);
                traceStatic.TraceInfo("CollectExportSettings: File location = '{0}'.", exportSettings.FileLocation);
                traceStatic.TraceInfo("CollectExportSettings: Base filename = '{0}'.", exportSettings.BaseFileName);
                traceStatic.TraceInfo("CollectExportSettings: Include versions = '{0}'.", exportSettings.IncludeVersions);
                traceStatic.TraceInfo("CollectExportSettings: Log file path = '{0}'.", exportSettings.LogFilePath);
                traceStatic.TraceInfo("CollectExportSettings: Include security = '{0}'.", exportSettings.IncludeSecurity);
            }

            WizardExportSettings weSettings = new WizardExportSettings(exportSettings, exportObjectDetails);

            if (traceSwitchStatic.TraceVerbose)
            {
                traceStatic.TraceVerbose("CollectExportSettings: Leaving CollectExportSettings().");
            }

            return(weSettings);
        }
コード例 #29
0
        private static void storeLargestScopedObject(SPExportSettings ExportSettings)
        {
            List<SPObjectData> objects = new List<SPObjectData>();

            foreach (SPExportObject exportObject in ExportSettings.ExportObjects)
            {
                objects.Add(new SPObjectData(exportObject.Id, exportObject.Url, exportObject.Url, exportObject.Type, 
                    exportObject.IncludeDescendants));
            }

            storeLargestScopedObject(objects);
        }
コード例 #30
0
ファイル: WizardDeployment.cs プロジェクト: vjohnson01/Tools
        internal static WizardExportSettings CollectExportSettings(XmlTextReader exportSettingsXml)
        {
            if (traceSwitchStatic.TraceVerbose)
            {
                traceStatic.TraceVerbose("CollectExportSettings: Entered CollectExportSettings().");
            }

            // create SPExportSettings object..
            SPExportSettings exportSettings = new SPExportSettings();
            List<SPObjectData> exportObjectDetails = new List<SPObjectData>();

            if (exportSettingsXml.Name != "ExportSettings")
            {
                exportSettingsXml.Read();
            }

            if (exportSettingsXml.Name == "ExportSettings")
            {
                if (exportSettingsXml.MoveToAttribute("SiteUrl"))
                {
                    exportSettings.SiteUrl = exportSettingsXml.Value;
                }
                if (exportSettingsXml.MoveToAttribute("ExcludeDependencies"))
                {
                    exportSettings.ExcludeDependencies = bool.Parse(exportSettingsXml.Value);
                }
                if (exportSettingsXml.MoveToAttribute("ExportMethod"))
                {
                    exportSettings.ExportMethod =
                        (SPExportMethodType)Enum.Parse(typeof(SPExportMethodType), exportSettingsXml.Value);
                }
                if (exportSettingsXml.MoveToAttribute("IncludeVersions"))
                {
                    exportSettings.IncludeVersions =
                        (SPIncludeVersions)Enum.Parse(typeof(SPIncludeVersions), exportSettingsXml.Value);
                }
                if (exportSettingsXml.MoveToAttribute("IncludeSecurity"))
                {
                    exportSettings.IncludeSecurity =
                        (SPIncludeSecurity)Enum.Parse(typeof(SPIncludeSecurity), exportSettingsXml.Value);
                }
                if (exportSettingsXml.MoveToAttribute("FileCompression"))
                {
                    exportSettings.FileCompression = bool.Parse(exportSettingsXml.Value);
                }
                if (exportSettingsXml.MoveToAttribute("FileLocation"))
                {
                    exportSettings.FileLocation = exportSettingsXml.Value;
                }
                if (exportSettingsXml.MoveToAttribute("BaseFileName"))
                {
                    exportSettings.BaseFileName = exportSettingsXml.Value;
                }
                if (exportSettingsXml.MoveToAttribute("IncludeSecurity"))
                {
                    exportSettings.IncludeSecurity =
                        (SPIncludeSecurity)Enum.Parse(typeof(SPIncludeSecurity), exportSettingsXml.Value);
                }

                exportSettingsXml.MoveToElement();
            }

            while (exportSettingsXml.Read())
            {
                if (exportSettingsXml.Name == "DeploymentObject")
                {
                    SPExportObject exportObject = new SPExportObject();
                    SPObjectData exportObjectData = new SPObjectData();

                    if (exportSettingsXml.MoveToAttribute("Id"))
                    {
                        Guid gID = new Guid(exportSettingsXml.Value);
                        exportObject.Id = gID;
                        exportObjectData.ID = gID;
                    }
                    if (exportSettingsXml.MoveToAttribute("Type"))
                    {
                        SPDeploymentObjectType type = (SPDeploymentObjectType)
                            Enum.Parse(typeof(SPDeploymentObjectType), exportSettingsXml.Value);
                        exportObject.Type = type;
                        exportObjectData.ObjectType = type;
                    }
                    if (exportSettingsXml.MoveToAttribute("ExcludeChildren"))
                    {
                        bool bExcludeChildren = bool.Parse(exportSettingsXml.Value);
                        exportObject.ExcludeChildren = bExcludeChildren;
                        exportObjectData.ExcludeChildren = bExcludeChildren;
                    }
                    if (exportSettingsXml.MoveToAttribute("IncludeDescendants"))
                    {
                        SPIncludeDescendants includeDescs = (SPIncludeDescendants)
                                                            Enum.Parse(typeof(SPIncludeDescendants),
                                                                       exportSettingsXml.Value);
                        exportObject.IncludeDescendants = includeDescs;
                        exportObjectData.IncludeDescendents = includeDescs;
                    }
                    if (exportSettingsXml.MoveToAttribute("Url"))
                    {
                        exportObject.Url = exportSettingsXml.Value;
                        exportObjectData.Url = exportSettingsXml.Value;
                    }
                    if (exportSettingsXml.MoveToAttribute("Title"))
                    {
                        exportObjectData.Title = exportSettingsXml.Value;
                    }

                    exportSettings.ExportObjects.Add(exportObject);
                    exportObjectDetails.Add(exportObjectData);
                }
            }
            
            exportSettingsXml.Close();

            // set other properties which aren't tied to values in XML..
            exportSettings.TestRun = false;
            exportSettings.OverwriteExistingDataFile = true;
            exportSettings.LogFilePath = string.Format("{0}\\{1}.Export.log",
                exportSettings.FileLocation, exportSettings.BaseFileName);
            
            if (traceSwitchStatic.TraceInfo)
            {
                traceStatic.TraceInfo("CollectExportSettings: Using site URL '{0}'.", exportSettings.SiteUrl);
                traceStatic.TraceInfo("CollectExportSettings: Exclude dependencies IDs = '{0}'.", exportSettings.ExcludeDependencies);
                traceStatic.TraceInfo("CollectExportSettings: Export method = '{0}'.", exportSettings.ExportMethod);
                traceStatic.TraceInfo("CollectExportSettings: File location = '{0}'.", exportSettings.FileLocation);
                traceStatic.TraceInfo("CollectExportSettings: Base filename = '{0}'.", exportSettings.BaseFileName);
                traceStatic.TraceInfo("CollectExportSettings: Include versions = '{0}'.", exportSettings.IncludeVersions);
                traceStatic.TraceInfo("CollectExportSettings: Log file path = '{0}'.", exportSettings.LogFilePath);
                traceStatic.TraceInfo("CollectExportSettings: Include security = '{0}'.", exportSettings.IncludeSecurity);
            }

            WizardExportSettings weSettings = new WizardExportSettings(exportSettings, exportObjectDetails);

            if (traceSwitchStatic.TraceVerbose)
            {
                traceStatic.TraceVerbose("CollectExportSettings: Leaving CollectExportSettings().");
            }

            return weSettings;
        }
コード例 #31
0
        /// <summary>
        /// Copies the specified source list to the target URL.
        /// </summary>
        /// <param name="directory">The directory.</param>
        /// <param name="compressFile">if set to <c>true</c> [compress file].</param>
        /// <param name="includeusersecurity">if set to <c>true</c> [includeusersecurity].</param>
        /// <param name="excludeDependencies">if set to <c>true</c> [exclude dependencies].</param>
        /// <param name="haltOnFatalError">if set to <c>true</c> [halt on fatal error].</param>
        /// <param name="haltOnWarning">if set to <c>true</c> [halt on warning].</param>
        /// <param name="versions">The versions.</param>
        /// <param name="updateVersions">The update versions.</param>
        /// <param name="suppressAfterEvents">if set to <c>true</c> [suppress after events].</param>
        /// <param name="copySecurity">if set to <c>true</c> [copy security].</param>
        /// <param name="deleteSource">if set to <c>true</c> [delete source].</param>
        /// <param name="logFile">if set to <c>true</c> [log file].</param>
        /// <param name="quiet">if set to <c>true</c> [quiet].</param>
        internal void Copy(string directory, bool compressFile, int cabSize, bool includeusersecurity, bool excludeDependencies, bool haltOnFatalError, bool haltOnWarning, SPIncludeVersions versions, SPUpdateVersions updateVersions, bool suppressAfterEvents, bool copySecurity, bool deleteSource, bool logFile, bool quiet, SPIncludeDescendants includeDescendents, bool useSqlSnapshot, bool excludeChildren, bool retainObjectIdentity)
        {
            if (string.IsNullOrEmpty(directory))
                directory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            string filename = directory;
            if (compressFile)
                filename = Path.Combine(directory, "temp.cmp");

            SPExportObject exportObject = new SPExportObject();
            SPExportSettings exportSettings = new SPExportSettings();
            exportSettings.ExcludeDependencies = excludeDependencies;
            SPExport export = new SPExport(exportSettings);

            exportObject.Type = SPDeploymentObjectType.List;
            exportObject.IncludeDescendants = includeDescendents;
            exportObject.ExcludeChildren = excludeChildren;
            StsAdm.OperationHelpers.ExportHelper.SetupExportObjects(exportSettings, cabSize, compressFile, filename, haltOnFatalError, haltOnWarning, includeusersecurity, logFile, true, quiet, versions);

            ExportList.PerformExport(export, exportObject, exportSettings, logFile, quiet, m_sourceUrl, useSqlSnapshot);

            SPImportSettings importSettings = new SPImportSettings();
            SPImport import = new SPImport(importSettings);

            StsAdm.OperationHelpers.ImportHelper.SetupImportObject(importSettings, compressFile, filename, haltOnFatalError, haltOnWarning, includeusersecurity, logFile, quiet, updateVersions, retainObjectIdentity, suppressAfterEvents);

            try
            {
                m_targetSite = new SPSite(m_targetUrl);
                m_targetWeb = m_targetSite.AllWebs[Utilities.GetServerRelUrlFromFullUrl(m_targetUrl)];

                PerformImport(import, importSettings, logFile, m_targetUrl);

                // If the list is a discussion list then attempt to resolve flattened threads.
                //if (m_targetList != null)
                //    SiteCollectionSettings.RepairSiteCollectionImportedFromSubSite.RepairDiscussionList(m_targetSite, m_targetList);

                if (!logFile && !deleteSource)
                {
                    Directory.Delete(directory, true);
                }
                else if (logFile && !deleteSource)
                {
                    foreach (string s in Directory.GetFiles(directory))
                    {
                        FileInfo file = new FileInfo(s);
                        if (file.Extension == ".log")
                            continue;
                        file.Delete();
                    }
                }

                if (deleteSource || copySecurity)
                {
                    using (SPSite sourceSite = new SPSite(m_sourceUrl))
                    using (SPWeb sourceWeb = sourceSite.OpenWeb())
                    {
                        SPList sourceList = Utilities.GetListFromViewUrl(sourceWeb, m_sourceUrl);

                        if (sourceList != null)
                        {
                            // If the user has chosen to include security then assume they mean for all the settings to match
                            // the source - copy those settings using the CopyListSecurity operation.
                            if (copySecurity)
                            {
                                Common.Lists.CopyListSecurity.CopySecurity(sourceList, m_targetList, m_targetWeb, true, quiet);
                            }

                            // If the user wants the source deleted (move operation) then delete using the DeleteList operation.
                            if (deleteSource)
                            {
                                DeleteList.Delete(sourceList, true);
                                Console.WriteLine("Source list deleted.  You can find the exported list here: " +
                                                  directory);
                            }
                        }
                    }
                }
            }
            finally
            {
                if (m_targetSite != null)
                    m_targetSite.Dispose();
                if (m_targetWeb != null)
                    m_targetWeb.Dispose();
            }
        }
コード例 #32
0
        /// <summary>
        /// Copies the specified source list to the target URL.
        /// </summary>
        /// <param name="directory">The directory.</param>
        /// <param name="compressFile">if set to <c>true</c> [compress file].</param>
        /// <param name="includeusersecurity">if set to <c>true</c> [includeusersecurity].</param>
        /// <param name="excludeDependencies">if set to <c>true</c> [exclude dependencies].</param>
        /// <param name="haltOnFatalError">if set to <c>true</c> [halt on fatal error].</param>
        /// <param name="haltOnWarning">if set to <c>true</c> [halt on warning].</param>
        /// <param name="versions">The versions.</param>
        /// <param name="updateVersions">The update versions.</param>
        /// <param name="suppressAfterEvents">if set to <c>true</c> [suppress after events].</param>
        /// <param name="copySecurity">if set to <c>true</c> [copy security].</param>
        /// <param name="deleteSource">if set to <c>true</c> [delete source].</param>
        /// <param name="logFile">if set to <c>true</c> [log file].</param>
        /// <param name="quiet">if set to <c>true</c> [quiet].</param>
        internal void Copy(string directory, bool compressFile, int cabSize, bool includeusersecurity, bool excludeDependencies, bool haltOnFatalError, bool haltOnWarning, SPIncludeVersions versions, SPUpdateVersions updateVersions, bool suppressAfterEvents, bool copySecurity, bool deleteSource, bool logFile, bool quiet, SPIncludeDescendants includeDescendents, bool useSqlSnapshot, bool excludeChildren, bool retainObjectIdentity)
        {
            if (string.IsNullOrEmpty(directory))
            {
                directory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            }
            string filename = directory;

            if (compressFile)
            {
                filename = Path.Combine(directory, "temp.cmp");
            }

            SPExportObject   exportObject   = new SPExportObject();
            SPExportSettings exportSettings = new SPExportSettings();

            exportSettings.ExcludeDependencies = excludeDependencies;
            SPExport export = new SPExport(exportSettings);

            exportObject.Type = SPDeploymentObjectType.List;
            exportObject.IncludeDescendants = includeDescendents;
            exportObject.ExcludeChildren    = excludeChildren;
            StsAdm.OperationHelpers.ExportHelper.SetupExportObjects(exportSettings, cabSize, compressFile, filename, haltOnFatalError, haltOnWarning, includeusersecurity, logFile, true, quiet, versions);

            ExportList.PerformExport(export, exportObject, exportSettings, logFile, quiet, m_sourceUrl, useSqlSnapshot);

            SPImportSettings importSettings = new SPImportSettings();
            SPImport         import         = new SPImport(importSettings);

            StsAdm.OperationHelpers.ImportHelper.SetupImportObject(importSettings, compressFile, filename, haltOnFatalError, haltOnWarning, includeusersecurity, logFile, quiet, updateVersions, retainObjectIdentity, suppressAfterEvents);

            try
            {
                m_targetSite = new SPSite(m_targetUrl);
                m_targetWeb  = m_targetSite.AllWebs[Utilities.GetServerRelUrlFromFullUrl(m_targetUrl)];

                PerformImport(import, importSettings, logFile, m_targetUrl);

                // If the list is a discussion list then attempt to resolve flattened threads.
                //if (m_targetList != null)
                //    SiteCollectionSettings.RepairSiteCollectionImportedFromSubSite.RepairDiscussionList(m_targetSite, m_targetList);

                if (!logFile && !deleteSource)
                {
                    Directory.Delete(directory, true);
                }
                else if (logFile && !deleteSource)
                {
                    foreach (string s in Directory.GetFiles(directory))
                    {
                        FileInfo file = new FileInfo(s);
                        if (file.Extension == ".log")
                        {
                            continue;
                        }
                        file.Delete();
                    }
                }

                if (deleteSource || copySecurity)
                {
                    using (SPSite sourceSite = new SPSite(m_sourceUrl))
                        using (SPWeb sourceWeb = sourceSite.OpenWeb())
                        {
                            SPList sourceList = Utilities.GetListFromViewUrl(sourceWeb, m_sourceUrl);

                            if (sourceList != null)
                            {
                                // If the user has chosen to include security then assume they mean for all the settings to match
                                // the source - copy those settings using the CopyListSecurity operation.
                                if (copySecurity)
                                {
                                    Common.Lists.CopyListSecurity.CopySecurity(sourceList, m_targetList, m_targetWeb, true, quiet);
                                }

                                // If the user wants the source deleted (move operation) then delete using the DeleteList operation.
                                if (deleteSource)
                                {
                                    DeleteList.Delete(sourceList, true);
                                    Console.WriteLine("Source list deleted.  You can find the exported list here: " +
                                                      directory);
                                }
                            }
                        }
                }
            }
            finally
            {
                if (m_targetSite != null)
                {
                    m_targetSite.Dispose();
                }
                if (m_targetWeb != null)
                {
                    m_targetWeb.Dispose();
                }
            }
        }