Ejemplo n.º 1
0
        /// <summary>
        /// Exports the site.
        /// </summary>
        /// <param name="sourceurl">The sourceurl.</param>
        /// <param name="haltOnWarning">if set to <c>true</c> [halt on warning].</param>
        /// <param name="haltOnFatalError">if set to <c>true</c> [halt on fatal error].</param>
        /// <param name="noFileCompression">if set to <c>true</c> [no file compression].</param>
        /// <param name="includeUserSecurity">if set to <c>true</c> [include user security].</param>
        /// <param name="quiet">if set to <c>true</c> [quiet].</param>
        /// <param name="versions">The versions.</param>
        /// <param name="cabSize">Size of the CAB.</param>
        /// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
        /// <param name="logFile">if set to <c>true</c> [log file].</param>
        /// <param name="filename">The filename.</param>
        /// <returns></returns>
        public static string ExportSite(string sourceurl,
                                        bool haltOnWarning,
                                        bool haltOnFatalError,
                                        bool noFileCompression,
                                        bool includeUserSecurity,
                                        bool quiet,
                                        SPIncludeVersions versions,
                                        int cabSize,
                                        bool overwrite,
                                        bool logFile,
                                        string filename)
        {
            /**
             * stsadm.exe -o export
             * -url <URL to be exported>
             * -filename <export file name>
             * [-overwrite]
             * [-includeusersecurity]
             * [-haltonwarning]
             * [-haltonfatalerror]
             * [-nologfile]
             * [-versions <1-4>
             * 1 - Last major version for files and list items (default)
             * 2 - The current version, either the last major or the last minor
             * 3 - Last major and last minor version for files and list items
             * 4 - All versions for files and list items]
             * [-cabsize <integer from 1-1024 megabytes> (default: 25)]
             * [-nofilecompression]
             * [-quiet]
             * */

            string command = string.Format(" -o export -url \"{0}\"{2}{3}{4}{5} -versions {6}{7}{8}{9}{10} -filename \"{1}\"",
                                           sourceurl,
                                           filename,
                                           (haltOnWarning ? " -haltonwarning" : ""),
                                           (haltOnFatalError ? " -haltonfatalerror" : ""),
                                           (noFileCompression ? " -nofilecompression" : ""),
                                           (includeUserSecurity ? " -includeusersecurity" : ""),
                                           (int)versions,
                                           (cabSize > 0 ? " -cabsize " + cabSize : ""),
                                           (quiet ? " -quiet" : ""),
                                           (!logFile ? " -nologfile" : ""),
                                           (overwrite ? " -overwrite" : ""));

            if (Utilities.RunStsAdmOperation(command, quiet) != 0)
            {
                throw new SPException("Error occured exporting site.\r\nCOMMAND: " + command);
            }

            // If we're using file compression then we need to add the "cmp" extension that the export tool automatically appends.
            if (!noFileCompression)
            {
                filename += ".cmp";
            }

            return(filename);
        }
        protected override void InternalProcessRecord()
        {
            using (SPWeb targetWeb = TargetWeb.Read())
            {
                SPList sourceList = SourceList.Read();
                try
                {
                    bool   compressFile        = !NoFileCompression.IsPresent;
                    bool   quiet               = !Verbose;
                    bool   haltOnWarning       = HaltOnWarning.IsPresent;
                    bool   haltOnFatalError    = HaltOnError.IsPresent;
                    bool   includeusersecurity = IncludeUserSecurity.IsPresent;
                    bool   excludeDependencies = !IncludeDependencies.IsPresent;
                    bool   copySecurity        = includeusersecurity;
                    bool   logFile             = !NoLogFile.IsPresent;
                    bool   deleteSource        = DeleteSource.IsPresent;
                    string directory           = null;
                    if (!string.IsNullOrEmpty(Path))
                    {
                        directory = Path;
                    }
                    bool suppressAfterEvents = SuppressAfterEvents.IsPresent;
                    bool retargetLinks       = RetargetLinks.IsPresent;

                    SPIncludeVersions versions = SPIncludeVersions.All;
                    if (IncludeVersions.HasValue)
                    {
                        versions = IncludeVersions.Value;
                    }

                    SPUpdateVersions updateVersions = SPUpdateVersions.Append;
                    if (UpdateVersions.HasValue)
                    {
                        updateVersions = UpdateVersions.Value;
                    }

                    SPIncludeDescendants includeDescendents = SPIncludeDescendants.All;
                    if (IncludeDescendants.HasValue)
                    {
                        includeDescendents = IncludeDescendants.Value;
                    }

                    bool useSqlSnapshot  = UseSqlSnapshot.IsPresent;
                    bool excludeChildren = ExcludeChildren.IsPresent;
                    Common.Lists.ImportList importList = new Common.Lists.ImportList(sourceList, targetWeb, retargetLinks);

                    importList.Copy(directory, compressFile, CompressionSize, includeusersecurity, excludeDependencies, haltOnFatalError, haltOnWarning, versions, updateVersions, suppressAfterEvents, copySecurity, deleteSource, logFile, quiet, includeDescendents, useSqlSnapshot, excludeChildren, RetainObjectIdentity);
                }
                finally
                {
                    targetWeb.Site.Dispose();
                    sourceList.ParentWeb.Dispose();
                    sourceList.ParentWeb.Site.Dispose();
                }
            }
        }
        /// <summary>
        /// Exports the site.
        /// </summary>
        /// <param name="sourceurl">The sourceurl.</param>
        /// <param name="haltOnWarning">if set to <c>true</c> [halt on warning].</param>
        /// <param name="haltOnFatalError">if set to <c>true</c> [halt on fatal error].</param>
        /// <param name="noFileCompression">if set to <c>true</c> [no file compression].</param>
        /// <param name="includeUserSecurity">if set to <c>true</c> [include user security].</param>
        /// <param name="quiet">if set to <c>true</c> [quiet].</param>
        /// <param name="versions">The versions.</param>
        /// <param name="cabSize">Size of the CAB.</param>
        /// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
        /// <param name="logFile">if set to <c>true</c> [log file].</param>
        /// <param name="filename">The filename.</param>
        /// <returns></returns>
        public static string ExportSite(string sourceurl, 
            bool haltOnWarning, 
            bool haltOnFatalError, 
            bool noFileCompression, 
            bool includeUserSecurity, 
            bool quiet,
            SPIncludeVersions versions,
            int cabSize,
            bool overwrite,
            bool logFile,
            string filename)
        {
            /**
            stsadm.exe -o export
            -url <URL to be exported>
            -filename <export file name>
            [-overwrite]
            [-includeusersecurity]
            [-haltonwarning]
            [-haltonfatalerror]
            [-nologfile]
            [-versions <1-4>
               1 - Last major version for files and list items (default)
               2 - The current version, either the last major or the last minor
               3 - Last major and last minor version for files and list items
               4 - All versions for files and list items]
            [-cabsize <integer from 1-1024 megabytes> (default: 25)]
            [-nofilecompression]
            [-quiet]
             * */

            string command = string.Format(" -o export -url \"{0}\"{2}{3}{4}{5} -versions {6}{7}{8}{9}{10} -filename \"{1}\"",
                sourceurl,
                filename,
                (haltOnWarning ? " -haltonwarning" : ""),
                (haltOnFatalError ? " -haltonfatalerror" : ""),
                (noFileCompression ? " -nofilecompression" : ""),
                (includeUserSecurity ? " -includeusersecurity" : ""),
                (int)versions,
                (cabSize > 0 ? " -cabsize " + cabSize : ""),
                (quiet ? " -quiet" : ""),
                (!logFile ? " -nologfile" : ""),
                (overwrite ? " -overwrite" : ""));

            if (Utilities.RunStsAdmOperation(command, quiet) != 0)
                throw new SPException("Error occured exporting site.\r\nCOMMAND: " + command);

            // If we're using file compression then we need to add the "cmp" extension that the export tool automatically appends.
            if (!noFileCompression)
                filename += ".cmp";

            return filename;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Runs the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="keyValues">The key values.</param>
        /// <param name="output">The output.</param>
        /// <returns></returns>
        public override int Execute(string command, System.Collections.Specialized.StringDictionary keyValues, out string output)
        {
            output = string.Empty;

            string sourceUrl           = Params["sourceurl"].Value;
            string targetUrl           = Params["targeturl"].Value;
            bool   compressFile        = !Params["nofilecompression"].UserTypedIn;
            bool   quiet               = Params["quiet"].UserTypedIn;
            bool   haltOnWarning       = Params["haltonwarning"].UserTypedIn;
            bool   haltOnFatalError    = Params["haltonfatalerror"].UserTypedIn;
            bool   includeusersecurity = Params["includeusersecurity"].UserTypedIn;
            bool   excludeDependencies = Params["excludedependencies"].UserTypedIn;
            bool   copySecurity        = includeusersecurity;
            bool   logFile             = !Params["nologfile"].UserTypedIn;
            bool   deleteSource        = Params["deletesource"].UserTypedIn;
            string directory           = null;

            if (Params["temppath"].UserTypedIn)
            {
                directory = Params["temppath"].Value;
            }
            bool suppressAfterEvents   = Params["suppressafterevents"].UserTypedIn;
            bool retargetLinks         = Params["retargetlinks"].UserTypedIn;
            SPIncludeVersions versions = SPIncludeVersions.All;

            if (Params["versions"].UserTypedIn)
            {
                versions = (SPIncludeVersions)Enum.Parse(typeof(SPIncludeVersions), Params["versions"].Value);
            }
            SPUpdateVersions updateVersions = SPUpdateVersions.Append;

            if (Params["updateversions"].UserTypedIn)
            {
                updateVersions = (SPUpdateVersions)Enum.Parse(typeof(SPUpdateVersions), Params["updateversions"].Value);
            }
            SPIncludeDescendants includeDescendents = (SPIncludeDescendants)Enum.Parse(typeof(SPIncludeDescendants), Params["includedescendants"].Value, true);
            bool useSqlSnapshot  = Params["usesqlsnapshot"].UserTypedIn;
            bool excludeChildren = Params["excludechildren"].UserTypedIn;
            int  cabSize         = 0;

            if (Params["cabsize"].UserTypedIn)
            {
                cabSize = int.Parse(Params["cabsize"].Value);
            }

            Common.Lists.ImportList importList = new Common.Lists.ImportList(sourceUrl, targetUrl, retargetLinks);

            importList.Copy(directory, compressFile, cabSize, includeusersecurity, excludeDependencies, haltOnFatalError, haltOnWarning, versions, updateVersions, suppressAfterEvents, copySecurity, deleteSource, logFile, quiet, includeDescendents, useSqlSnapshot, excludeChildren, false);

            return((int)ErrorCodes.NoError);
        }
        /// <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);
        }
        /// <summary>
        /// Exports the site.
        /// </summary>
        /// <param name="sourceurl">The sourceurl.</param>
        /// <param name="haltOnWarning">if set to <c>true</c> [halt on warning].</param>
        /// <param name="haltOnFatalError">if set to <c>true</c> [halt on fatal error].</param>
        /// <param name="noFileCompression">if set to <c>true</c> [no file compression].</param>
        /// <param name="includeUserSecurity">if set to <c>true</c> [include user security].</param>
        /// <param name="quiet">if set to <c>true</c> [quiet].</param>
        /// <param name="versions">The versions.</param>
        /// <param name="cabSize">Size of the CAB.</param>
        /// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
        /// <param name="logFile">if set to <c>true</c> [log file].</param>
        /// <returns></returns>
        public static string ExportSite(string sourceurl,
            bool haltOnWarning,
            bool haltOnFatalError,
            bool noFileCompression,
            bool includeUserSecurity,
            bool quiet,
            SPIncludeVersions versions,
            int cabSize,
            bool overwrite,
            bool logFile)
        {
            string filename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            return
                ExportSite(sourceurl, haltOnWarning, haltOnFatalError, noFileCompression, includeUserSecurity, quiet,
                           versions, cabSize, overwrite, logFile, filename);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Exports the site.
        /// </summary>
        /// <param name="sourceurl">The sourceurl.</param>
        /// <param name="haltOnWarning">if set to <c>true</c> [halt on warning].</param>
        /// <param name="haltOnFatalError">if set to <c>true</c> [halt on fatal error].</param>
        /// <param name="noFileCompression">if set to <c>true</c> [no file compression].</param>
        /// <param name="includeUserSecurity">if set to <c>true</c> [include user security].</param>
        /// <param name="quiet">if set to <c>true</c> [quiet].</param>
        /// <param name="versions">The versions.</param>
        /// <param name="cabSize">Size of the CAB.</param>
        /// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
        /// <param name="logFile">if set to <c>true</c> [log file].</param>
        /// <returns></returns>
        public static string ExportSite(string sourceurl,
                                        bool haltOnWarning,
                                        bool haltOnFatalError,
                                        bool noFileCompression,
                                        bool includeUserSecurity,
                                        bool quiet,
                                        SPIncludeVersions versions,
                                        int cabSize,
                                        bool overwrite,
                                        bool logFile)
        {
            string filename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            return
                (ExportSite(sourceurl, haltOnWarning, haltOnFatalError, noFileCompression, includeUserSecurity, quiet,
                            versions, cabSize, overwrite, logFile, filename));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Runs the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="keyValues">The key values.</param>
        /// <param name="output">The output.</param>
        /// <returns></returns>
        public override int Execute(string command, System.Collections.Specialized.StringDictionary keyValues, out string output)
        {
            output = string.Empty;

            string url                 = Params["url"].Value;
            bool   compressFile        = !Params["nofilecompression"].UserTypedIn;
            string filename            = Params["filename"].Value;
            bool   overwrite           = Params["overwrite"].UserTypedIn;
            bool   quiet               = Params["quiet"].UserTypedIn;
            bool   haltOnWarning       = Params["haltonwarning"].UserTypedIn;
            bool   haltOnFatalError    = Params["haltonfatalerror"].UserTypedIn;
            bool   includeusersecurity = Params["includeusersecurity"].UserTypedIn;
            bool   excludeDependencies = Params["excludedependencies"].UserTypedIn;
            bool   logFile             = !Params["nologfile"].UserTypedIn;
            bool   useSqlSnapshot      = Params["usesqlsnapshot"].UserTypedIn;
            bool   excludeChildren     = Params["excludechildren"].UserTypedIn;

            int cabSize = 0;

            if (Params["cabsize"].UserTypedIn)
            {
                cabSize = int.Parse(Params["cabsize"].Value);
            }

            SPIncludeVersions versions = SPIncludeVersions.All;

            if (Params["versions"].UserTypedIn)
            {
                versions = (SPIncludeVersions)Enum.Parse(typeof(SPIncludeVersions), Params["versions"].Value);
            }
            SPIncludeDescendants includeDescendents = (SPIncludeDescendants)Enum.Parse(typeof(SPIncludeDescendants), Params["includedescendants"].Value, true);

            Common.Lists.ExportList.PerformExport(url, filename, compressFile, haltOnFatalError, haltOnWarning, includeusersecurity, cabSize, logFile, overwrite, quiet, versions, includeDescendents, excludeDependencies, useSqlSnapshot, excludeChildren);


            return((int)ErrorCodes.NoError);
        }
Ejemplo n.º 9
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);
        }
        /// <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();
            }
        }
        /// <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);
                }
            }
        }
Ejemplo n.º 12
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);
                }
            }
        }
Ejemplo n.º 13
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();
                }
            }
        }