Example #1
0
        internal SPObjectData GetSupplementaryData(SPExportObject ExportObject)
        {
            if (traceSwitchStatic.TraceVerbose)
            {
                traceStatic.TraceVerbose("GetSupplementaryData: Entered.");
            }

            SPObjectData foundObject = exportObjectDetails.Find(o => o.ID == ExportObject.Id);

            if (foundObject != null)
            {
                if (traceSwitchStatic.TraceInfo)
                {
                    traceStatic.TraceInfo("GetSupplementaryData: Found object with ID '{0}' in collection.", ExportObject.Id);
                }
            }
            else
            {
                if (traceSwitchStatic.TraceInfo)
                {
                    traceStatic.TraceInfo("GetSupplementaryData: Did not find object with ID '{0}' in collection, returning null.", ExportObject.Id);
                }
            }

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

            return(foundObject);
        }
Example #2
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;
     }
 }
Example #3
0
        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;
//            }
        }
Example #4
0
        public SPExportObjectInstance(ObjectInstance prototype)
            : base(prototype)
        {
            m_exportObject = new SPExportObject();

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

            });
        }
Example #6
0
        public SPExportObjectInstance(ObjectInstance prototype, SPExportObject exportObject)
            : this(prototype)
        {
            if (exportObject == null)
            {
                throw new ArgumentNullException("exportObject");
            }

            m_exportObject = exportObject;
        }
Example #7
0
 public static SPExportObject GetExportObject(SPList l)
 {
     var list = new SPExportObject()
     {
         Id = l.ID,
         ExcludeChildren = false,
         Url = l.RootFolder.Url,
         IncludeDescendants = SPIncludeDescendants.All,
         Type = SPDeploymentObjectType.List
     };
     return list;
 }
Example #8
0
 public static SPExportObject GetExportObject(Guid id, SPDeploymentObjectType type, string url)
 {
     var list = new SPExportObject()
     {
         Id = id,
         ExcludeChildren = false,
         Url = url,
         IncludeDescendants = SPIncludeDescendants.All,
         Type = type
     };
     return list;
 }
Example #9
0
        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;
            //            }
        }
Example #10
0
        public ArrayInstance ExportList(
            [JSDoc("The SharePoint list to export. Can be a SPListInstance, guid, uri or url string")]
            object list,
            [JSDoc("The target file path or null to autogenerate.")]
            object fileLocation,
            [JSDoc("The base file name or null to autogenerate.")]
            object baseFileName,
            [JSDoc("The log file path or null to use the default.")]
            object logFilePath,
            [JSDoc("The target drop location or null to keep in target folder.")]
            object dropLocation)
        {
            SPList spList;

            if (list is SPListInstance)
            {
                spList = (list as SPListInstance).List;
            }
            else if (list is GuidInstance)
            {
                var guid = (list as GuidInstance).Value;
                spList = SPBaristaContext.Current.Web.Lists[guid];
            }
            else if (list is UriInstance)
            {
                var uri = (list as UriInstance).Uri;
                spList = SPBaristaContext.Current.Web.GetList(uri.ToString());
            }
            else
            {
                var listTitle = TypeConverter.ToString(list);
                spList = SPBaristaContext.Current.Web.Lists.TryGetList(listTitle);
            }

            if (spList == null)
            {
                throw new JavaScriptException(Engine, "Error", "Could not locate a list with the specified argument.");
            }

            var exportObject = new SPExportObject
            {
                Id   = spList.ID,
                Type = SPDeploymentObjectType.List,
                IncludeDescendants = SPIncludeDescendants.All
            };

            return(ExportInternal(fileLocation, baseFileName, logFilePath, new List <SPExportObject> {
                exportObject
            }, dropLocation));
        }
Example #11
0
        public ArrayInstance ExportSite(
            [JSDoc("The SharePoint site to export. Can be a SPSiteInstance, guid, uri or url string")]
            object site,
            [JSDoc("The target file path or null to autogenerate.")]
            object fileLocation,
            [JSDoc("The base file name or null to autogenerate.")]
            object baseFileName,
            [JSDoc("The log file path or null to use the default.")]
            object logFilePath,
            [JSDoc("The target drop location or null to keep in target folder.")]
            object dropLocation)
        {
            SPSite spSite;

            if (site is SPSiteInstance)
            {
                spSite = (site as SPSiteInstance).Site;
            }
            else if (site is GuidInstance)
            {
                var guid = (site as GuidInstance).Value;
                spSite = new SPSite(guid, SPBaristaContext.Current.Site.UserToken);
            }
            else if (site is UriInstance)
            {
                var uri = (site as UriInstance).Uri;
                spSite = new SPSite(uri.ToString(), SPBaristaContext.Current.Site.UserToken);
            }
            else
            {
                var siteUrl = TypeConverter.ToString(site);
                spSite = new SPSite(siteUrl, SPBaristaContext.Current.Site.UserToken);
            }

            if (spSite == null)
            {
                throw new JavaScriptException(Engine, "Error", "Could not locate a site with the specified argument.");
            }

            var exportObject = new SPExportObject
            {
                Id   = spSite.ID,
                Type = SPDeploymentObjectType.Site,
                IncludeDescendants = SPIncludeDescendants.All
            };

            return(ExportInternal(fileLocation, baseFileName, logFilePath, new List <SPExportObject> {
                exportObject
            }, dropLocation));
        }
        /// <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);
        }
Example #13
0
        public ArrayInstance ExportFolder(
            [JSDoc("The SharePoint folder to export. Can be a SPFolderInstance, guid, uri or url string")]
            object folder,
            [JSDoc("The target file path or null to autogenerate.")]
            object fileLocation,
            [JSDoc("The base file name or null to autogenerate.")]
            object baseFileName,
            [JSDoc("The log file path or null to use the default.")]
            object logFilePath,
            [JSDoc("The target drop location or null to keep in target folder.")]
            object dropLocation)
        {
            SPFolder spFolder;

            if (folder is SPFolderInstance)
            {
                spFolder = (folder as SPFolderInstance).Folder;
            }
            else if (folder is GuidInstance)
            {
                var guid = (folder as GuidInstance).Value;
                spFolder = SPBaristaContext.Current.Web.GetFolder(guid);
            }
            else if (folder is UriInstance)
            {
                var uri = (folder as UriInstance).Uri;
                spFolder = SPBaristaContext.Current.Web.GetFolder(uri.ToString());
            }
            else
            {
                var folderUri = TypeConverter.ToString(folder);
                spFolder = SPBaristaContext.Current.Web.GetFolder(folderUri);
            }

            if (spFolder == null)
            {
                throw new JavaScriptException(Engine, "Error", "Could not locate a file with the specified argument.");
            }

            var exportObject = new SPExportObject
            {
                Id   = spFolder.UniqueId,
                Type = SPDeploymentObjectType.Folder,
                IncludeDescendants = SPIncludeDescendants.All
            };

            return(ExportInternal(fileLocation, baseFileName, logFilePath, new List <SPExportObject> {
                exportObject
            }, dropLocation));
        }
Example #14
0
        public ArrayInstance ExportWeb(
            [JSDoc("The SharePoint web to export. Can be a SPWebInstance, guid, uri or url string")]
            object web,
            [JSDoc("The target file path or null to autogenerate.")]
            object fileLocation,
            [JSDoc("The base file name or null to autogenerate.")]
            object baseFileName,
            [JSDoc("The log file path or null to use the default.")]
            object logFilePath,
            [JSDoc("The target drop location or null to keep in target folder.")]
            object dropLocation)
        {
            SPWeb spWeb;

            if (web is SPWebInstance)
            {
                spWeb = (web as SPWebInstance).Web;
            }
            else if (web is GuidInstance)
            {
                var guid = (web as GuidInstance).Value;
                spWeb = SPBaristaContext.Current.Site.OpenWeb(guid);
            }
            else if (web is UriInstance)
            {
                var uri = (web as UriInstance).Uri;
                spWeb = SPBaristaContext.Current.Site.OpenWeb(uri.ToString());
            }
            else
            {
                var webTitle = TypeConverter.ToString(web);
                spWeb = SPBaristaContext.Current.Site.OpenWeb(webTitle);
            }

            if (spWeb == null)
            {
                throw new JavaScriptException(Engine, "Error", "Could not locate a web with the specified argument.");
            }

            var exportObject = new SPExportObject
            {
                Id   = spWeb.ID,
                Type = SPDeploymentObjectType.Web,
                IncludeDescendants = SPIncludeDescendants.All
            };

            return(ExportInternal(fileLocation, baseFileName, logFilePath, new List <SPExportObject> {
                exportObject
            }, dropLocation));
        }
Example #15
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);
        }
Example #16
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;
            }
        }
Example #17
0
        internal SPObjectData GetSupplementaryData(SPExportObject ExportObject)
        {
            if (traceSwitchStatic.TraceVerbose)
            {
                traceStatic.TraceVerbose("GetSupplementaryData: Entered.");
            }

            SPObjectData foundObject = exportObjectDetails.Find(o => o.ID == ExportObject.Id);
            if (foundObject != null)
            {
                if (traceSwitchStatic.TraceInfo)
                {
                    traceStatic.TraceInfo("GetSupplementaryData: Found object with ID '{0}' in collection.", ExportObject.Id);
                } 
            }
            else
            {
                if (traceSwitchStatic.TraceInfo)
                {
                    traceStatic.TraceInfo("GetSupplementaryData: Did not find object with ID '{0}' in collection, returning null.", ExportObject.Id);
                } 
            }

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

            return foundObject;
        }
        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);
            }
        }
Example #20
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);
                    }
                }
            }
        }
Example #21
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);
        }
        /// <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();
            }
        }
Example #23
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;
        }
        /// <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);
                    }
                }
            }
        }
Example #25
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();
                }
            }
        }