Ejemplo n.º 1
0
        /// <summary>
        /// Performs the import.
        /// </summary>
        /// <param name="import">The import.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="logFile">if set to <c>true</c> [log file].</param>
        /// <param name="targetUrl">The Source URL.</param>
        internal void PerformImport(SPImport import, SPImportSettings settings, bool logFile, string targetUrl)
        {
            using (SPSite site = new SPSite(targetUrl))
            {
                ExportList.ValidateUser(site);

                using (SPWeb web = site.OpenWeb())
                {
                    settings.SiteUrl = site.Url;
                    settings.WebUrl  = web.Url;
                }
            }
            import.ObjectImported += new EventHandler <SPObjectImportedEventArgs>(OnImported);

            try
            {
                import.Run();
            }
            finally
            {
                if (logFile)
                {
                    Console.WriteLine();
                    Console.WriteLine("Log file generated: ");
                    Console.WriteLine("\t{0}", settings.LogFilePath);
                    Console.WriteLine();
                }
            }
        }
Ejemplo n.º 2
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;
//            }
        }
Ejemplo n.º 3
0
        public SPImportSettingsInstance(ObjectInstance prototype)
            : base(prototype)
        {
            m_importSettings = new SPImportSettings();

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

            });
        }
Ejemplo n.º 5
0
        public SPImportSettingsInstance(ObjectInstance prototype, SPImportSettings importSettings)
            : this(prototype)
        {
            if (importSettings == null)
            {
                throw new ArgumentNullException("importSettings");
            }

            m_importSettings = importSettings;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Provisions a Subweb at the specified location, based on a previously exported template file (.cmp)
        /// in the path specified.
        /// </summary>
        /// <param name="destinationSiteUrl">The Parent Website the new site should be created under, i.e.: 'http://sharepoint/sites/MyCollection/MyParentWeb'</param>
        /// <param name="destinationWebUrl">The relative URL to assign to the imported website.  i.e.: 'MyNewWebSite'</param>
        /// <param name="pathToTemplateFile">The File Location where an existing template file with extension .CMP can be found. i.e.: @"C:\MyPath\Templates\SiteTemplate.cmp"</param>
        /// <returns>Boolean, True or False, indicative of success.</returns>
        public static bool importSpWeb(string destinationSiteUrl, string destinationWebUrl, string pathToTemplateFile)
        {
            bool   success      = false;
            string importedSite = null;

            try
            {
                using (SPSite site = new SPSite(destinationSiteUrl))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPImportSettings importSettings = new SPImportSettings();
                        importSettings.CommandLineVerbose = true; // uncomment for testing
                        importSettings.SiteUrl            = site.Url;
                        importSettings.WebUrl             = web.Url;
                        importSettings.FileLocation       = Path.GetDirectoryName(pathToTemplateFile);
                        importSettings.BaseFileName       = Path.GetFileName(pathToTemplateFile);
                        importSettings.FileCompression    = true;
                        importSettings.IncludeSecurity    = SPIncludeSecurity.All;
                        importSettings.Validate();
                        SPImport import = new SPImport(importSettings);

                        import.ObjectImported += delegate(object delegateSender, SPObjectImportedEventArgs delegateArgs)
                        {
                            if (string.IsNullOrEmpty(importedSite))
                            {
                                importedSite = delegateArgs.TargetUrl;
                            }
                            return;
                        };
                        import.Run();

                        // The above brought in a new web, but it's identical to the template, including the URL and title.
                        // So let's get the new web and set its URL appropriately, and change the title to a temporary one.

                        using (SPWeb newWeb = site.OpenWeb(importedSite, true))
                        {
                            newWeb.Name = destinationWebUrl;
                            newWeb.AllProperties.SetProperty("Site_Created", DateTime.Now.ToString());
                            newWeb.Title = "Temporary Import Generated at " + newWeb.AllProperties["Site_Created"].ToString();
                            newWeb.Update();
                        }

                        success = true;
                    }
                }
            }
            catch (Exception ex)
            {
                success = false;
                log.addError("Could not create site from imported template file: " + ex.ToString());
                return(success);
            }
            return(success);
        }
        /// <summary>
        /// Sets up the import object.
        /// </summary>
        /// <param name="settings">The settings.</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> [includeusersecurity].</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="updateVersions">The update versions.</param>
        /// <param name="retainObjectIdentity">if set to <c>true</c> [retain object identity].</param>
        /// <param name="suppressAfterEvents">if set to <c>true</c> [suppress after events].</param>
        internal static void SetupImportObject(SPImportSettings settings, bool compressFile, string filename, bool haltOnFatalError, bool haltOnWarning, bool includeusersecurity, bool logFile, bool quiet, SPUpdateVersions updateVersions, bool retainObjectIdentity, bool suppressAfterEvents)
        {
            settings.CommandLineVerbose  = !quiet;
            settings.HaltOnNonfatalError = haltOnFatalError;
            settings.HaltOnWarning       = haltOnWarning;
            settings.FileCompression     = compressFile;
            settings.SuppressAfterEvents = suppressAfterEvents;

            if (!compressFile)
            {
                if (string.IsNullOrEmpty(filename) || !Directory.Exists(filename))
                {
                    throw new SPException(SPResource.GetString("DirectoryNotFoundExceptionMessage", new object[] { filename }));
                }
            }
            else if (string.IsNullOrEmpty(filename) || !File.Exists(filename))
            {
                throw new SPException(SPResource.GetString("FileNotFoundExceptionMessage", new object[] { filename }));
            }

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

            if (logFile)
            {
                if (!compressFile)
                {
                    settings.LogFilePath = Path.Combine(settings.FileLocation, "import.log");
                }
                else
                {
                    settings.LogFilePath = Path.Combine(settings.FileLocation, filename + ".import.log");
                }
            }


            if (includeusersecurity)
            {
                settings.IncludeSecurity  = SPIncludeSecurity.All;
                settings.UserInfoDateTime = SPImportUserInfoDateTimeOption.ImportAll;
            }
            settings.UpdateVersions       = updateVersions;
            settings.RetainObjectIdentity = retainObjectIdentity;
        }
Ejemplo n.º 8
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;
            //            }
        }
Ejemplo n.º 9
0
        public void PerformImport(bool compressFile, string filename, bool quiet, bool haltOnWarning, bool haltOnFatalError, bool includeusersecurity, bool logFile, bool retainObjectIdentity, bool copySecurity, bool suppressAfterEvents, SPUpdateVersions updateVersions)
        {
            SPImportSettings settings = new SPImportSettings();
            SPImport         import   = new SPImport(settings);

            StsAdm.OperationHelpers.ImportHelper.SetupImportObject(settings, 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, settings, 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 (includeusersecurity && !string.IsNullOrEmpty(m_sourceUrl) && copySecurity)
                {
                    using (SPSite sourceSite = new SPSite(m_sourceUrl))
                        using (SPWeb sourceWeb = sourceSite.OpenWeb())
                        {
                            SPList sourceList = Utilities.GetListFromViewUrl(sourceWeb, m_sourceUrl);

                            if (sourceList != null)
                            {
                                if (m_targetList != null)
                                {
                                    Common.Lists.CopyListSecurity.CopySecurity(sourceList, m_targetList, m_targetWeb, true, quiet);
                                }
                            }
                        }
                }
            }
            finally
            {
                if (m_targetSite != null)
                {
                    m_targetSite.Dispose();
                }
                if (m_targetWeb != null)
                {
                    m_targetWeb.Dispose();
                }
            }
        }
Ejemplo n.º 10
0
        public bool Import(SPWeb web, string filename)
        {
            SPImportSettings importSettings = new SPImportSettings();

            importSettings.BaseFileName = Helper.Instance.ExtractFileName(filename);
            importSettings.FileLocation = Helper.Instance.ExtractFolder(filename);
            importSettings.SiteUrl      = web.Url;

            importSettings.RetainObjectIdentity = false;
            importSettings.SuppressAfterEvents  = true;

            // DeleteLists(web);

            SPImport import = new SPImport(importSettings);

            import.Run();

            return(true);
        }
        protected void importButton_Click(object sender, EventArgs args)
        {
            //Create an ImportSettings object to configure the import
            SPImportSettings importSettings = new SPImportSettings();

            //Set the name and location of the import file
            importSettings.BaseFileName = "demoTasksExport.cmp";
            importSettings.FileLocation = @"C:\";
            //Set the URL of the site to import into
            importSettings.SiteUrl = "http://intranet.contoso.com";

            //Do the import
            SPImport import = new SPImport(importSettings);

            try
            {
                import.Run();
                resultsLabel.Text = "Import was successful";
            }
            catch (Exception ex)
            {
                resultsLabel.Text = "The Import caused an error: " + ex.Message;
            }
        }
        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);
            }
        }
Ejemplo n.º 13
0
        internal static WizardImportSettings CollectImportSettings(XmlTextReader importSettingsXml)
        {
            if (traceSwitchStatic.TraceVerbose)
            {
                traceStatic.TraceVerbose("CollectImportSettings: Entered CollectImportSettings().");
            }

            if (importSettingsXml.Name != "ImportSettings")
            {
                importSettingsXml.Read();
            }

            // create SPImportSettings object..
            SPImportSettings importSettings = new SPImportSettings();

            if (importSettingsXml.Name == "ImportSettings")
            {
                if (importSettingsXml.MoveToAttribute("SiteUrl"))
                {
                    importSettings.SiteUrl = importSettingsXml.Value;
                }
                if (importSettingsXml.MoveToAttribute("ImportWebUrl"))
                {
                    if (!string.IsNullOrEmpty(importSettingsXml.Value))
                    {
                        importSettings.WebUrl = importSettingsXml.Value;
                    }
                }
                if (importSettingsXml.MoveToAttribute("FileLocation"))
                {
                    importSettings.FileLocation = importSettingsXml.Value;
                }
                if (importSettingsXml.MoveToAttribute("BaseFileName"))
                {
                    importSettings.BaseFileName = importSettingsXml.Value;
                }
                if (importSettingsXml.MoveToAttribute("IncludeSecurity"))
                {
                    importSettings.IncludeSecurity = (SPIncludeSecurity)Enum.Parse(typeof(SPIncludeSecurity), importSettingsXml.Value);
                }
                if (importSettingsXml.MoveToAttribute("VersionOptions"))
                {
                    importSettings.UpdateVersions = (SPUpdateVersions)Enum.Parse(typeof(SPUpdateVersions), importSettingsXml.Value);
                }
                if (importSettingsXml.MoveToAttribute("RetainObjectIdentity"))
                {
                    importSettings.RetainObjectIdentity = bool.Parse(importSettingsXml.Value);
                }
                if (importSettingsXml.MoveToAttribute("FileCompression"))
                {
                    importSettings.FileCompression = bool.Parse(importSettingsXml.Value);
                }
                if (importSettingsXml.MoveToAttribute("UserInfoUpdate"))
                {
                    importSettings.UserInfoDateTime = (SPImportUserInfoDateTimeOption)Enum.Parse(typeof(SPImportUserInfoDateTimeOption), importSettingsXml.Value);
                }
            }

            importSettingsXml.Close();

            // set other properties which aren't tied to values in XML..
            importSettings.LogFilePath = string.Format("{0}\\{1}.Import.log",
                importSettings.FileLocation, importSettings.BaseFileName);
            
            if (traceSwitchStatic.TraceInfo)
            {
                traceStatic.TraceInfo("CollectImportSettings: Using site URL '{0}'.", importSettings.SiteUrl);
                traceStatic.TraceInfo("CollectImportSettings: Using web URL '{0}'.", importSettings.WebUrl);
                traceStatic.TraceInfo("CollectImportSettings: File location = '{0}'.", importSettings.FileLocation);
                traceStatic.TraceInfo("CollectImportSettings: Base filename = '{0}'.", importSettings.BaseFileName);
                traceStatic.TraceInfo("CollectImportSettings: Update versions = '{0}'.", importSettings.UpdateVersions);
                traceStatic.TraceInfo("CollectImportSettings: Log file path = '{0}'.", importSettings.LogFilePath);
                traceStatic.TraceInfo("CollectImportSettings: Include security = '{0}'.", importSettings.IncludeSecurity);
                traceStatic.TraceInfo("CollectImportSettings: Retain object identity = '{0}'.", importSettings.RetainObjectIdentity);
            }

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

            WizardImportSettings wiSettings = new WizardImportSettings(importSettings);
            return wiSettings;
        }
        protected override void InternalProcessRecord()
        {
            string path = base.Path;

            if (!base.NoFileCompression.IsPresent)
            {
                if (string.IsNullOrEmpty(path) || !File.Exists(path))
                {
                    throw new SPException(SPResource.GetString("FileNotFoundExceptionMessage", new object[] { path }));
                }
            }
            else if (string.IsNullOrEmpty(path) || !Directory.Exists(path))
            {
                throw new SPException(SPResource.GetString("DirectoryNotFoundExceptionMessage", new object[] { path }));
            }
            string url = this.Identity.Read().Url;

            if (base.ShouldProcess(string.Format("ShouldProcessImportWeb,{0},{1}", url, base.Path)))
            {
                SPImportSettings settings = new SPImportSettings();
                SPImport         import   = new SPImport(settings);
                base.SetDeploymentSettings(settings);
                if (base.IncludeUserSecurity.IsPresent)
                {
                    settings.IncludeSecurity  = SPIncludeSecurity.All;
                    settings.UserInfoDateTime = SPImportUserInfoDateTimeOption.ImportAll;
                }
                settings.SuppressAfterEvents = SuppressAfterEvents.IsPresent;
                settings.UpdateVersions      = this.UpdateVersions;
                char[] trimChars = new char[] { '/' };
                if (url[url.Length - 1] == '/')
                {
                    url = url.TrimEnd(trimChars);
                }
                settings.RetainObjectIdentity = RetainObjectIdentity.IsPresent;
                settings.SiteUrl = url;
                using (SPSite site = new SPSite(url))
                {
                    string str5;
                    Utilities.SplitUrl(Utilities.ConvertToServiceRelUrl(Utilities.GetServerRelUrlFromFullUrl(url), site.ServerRelativeUrl), out str5, out this.m_webName);
                    this.m_webParentUrl = site.ServerRelativeUrl;
                    if (!string.IsNullOrEmpty(str5))
                    {
                        if (!this.m_webParentUrl.EndsWith("/"))
                        {
                            this.m_webParentUrl = this.m_webParentUrl + "/";
                        }
                        this.m_webParentUrl = this.m_webParentUrl + str5;
                    }
                }
                if (this.m_webName == null)
                {
                    this.m_webName = string.Empty;
                }
                EventHandler <SPDeploymentEventArgs> handler = new EventHandler <SPDeploymentEventArgs>(this.OnStarted);
                import.Started += handler;
                try
                {
                    import.Run();
                }
                finally
                {
                    if (!base.NoLogFile.IsPresent)
                    {
                        Console.WriteLine();
                        Console.WriteLine(SPResource.GetString("ExportOperationLogFile", new object[0]));
                        Console.WriteLine("\t{0}", settings.LogFilePath);
                        Console.WriteLine();
                    }
                }
            }
        }
        /// <summary>
        /// Imports the site providing the option to retain the source objects ID values.  The source object
        /// must no longer exist in the target content database.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <param name="targeturl">The targeturl.</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="logFile">if set to <c>true</c> [log file].</param>
        /// <param name="retainObjectIdentity">if set to <c>true</c> [retain object identity].</param>
        /// <param name="updateVersions">The update versions.</param>
        /// <param name="suppressAfterEvents">if set to <c>true</c> [suppress after events].</param>
        public void ImportSite(string filename, string targeturl, bool haltOnWarning, bool haltOnFatalError, bool noFileCompression, bool includeUserSecurity, bool quiet, bool logFile, bool retainObjectIdentity, SPUpdateVersions updateVersions, bool suppressAfterEvents)
        {
            //if (!retainObjectIdentity)
            //{
            //    // Use the built in "import" command.
            //    ImportSite(filename, targeturl, haltOnWarning, haltOnFatalError, noFileCompression, includeUserSecurity,
            //               quiet, logFile, updateVersions);
            //    return;
            //}

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

            SetupImportObject(settings, !noFileCompression, filename, haltOnFatalError, haltOnWarning, includeUserSecurity, logFile, quiet, updateVersions, retainObjectIdentity, suppressAfterEvents);

            using (SPSite site = new SPSite(targeturl))
            {
                settings.SiteUrl = site.Url;
                Common.Lists.ExportList.ValidateUser(site);

                string dirName;
                Utilities.SplitUrl(Utilities.ConvertToServiceRelUrl(Utilities.GetServerRelUrlFromFullUrl(targeturl), site.ServerRelativeUrl), out dirName, out m_webName);
                m_webParentUrl = site.ServerRelativeUrl;
                if (!string.IsNullOrEmpty(dirName))
                {
                    if (!m_webParentUrl.EndsWith("/"))
                    {
                        m_webParentUrl = m_webParentUrl + "/";
                    }
                    m_webParentUrl = m_webParentUrl + dirName;
                }
                if (m_webName == null)
                {
                    m_webName = string.Empty;
                }
            }

            EventHandler <SPDeploymentEventArgs> handler = new EventHandler <SPDeploymentEventArgs>(OnSiteImportStarted);

            import.Started += handler;

            try
            {
                import.Run();
            }
            catch (SPException ex)
            {
                if (retainObjectIdentity && ex.Message.StartsWith("The Web site address ") && ex.Message.EndsWith(" is already in use."))
                {
                    throw new SPException(
                              "You cannot import the web because the source web still exists.  Either specify the \"-deletesource\" parameter or manually delete the source web and use the exported file.", ex);
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                Console.WriteLine();
                Console.WriteLine("Log file generated: ");
                Console.WriteLine("\t{0}", settings.LogFilePath);
                Console.WriteLine();
            }
        }
        /// <summary>
        /// Imports the site providing the option to retain the source objects ID values.  The source object
        /// must no longer exist in the target content database.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <param name="targeturl">The targeturl.</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="logFile">if set to <c>true</c> [log file].</param>
        /// <param name="retainObjectIdentity">if set to <c>true</c> [retain object identity].</param>
        /// <param name="updateVersions">The update versions.</param>
        /// <param name="suppressAfterEvents">if set to <c>true</c> [suppress after events].</param>
        public void ImportSite(string filename, string targeturl, bool haltOnWarning, bool haltOnFatalError, bool noFileCompression, bool includeUserSecurity, bool quiet, bool logFile, bool retainObjectIdentity, SPUpdateVersions updateVersions, bool suppressAfterEvents)
        {
            //if (!retainObjectIdentity)
            //{
            //    // Use the built in "import" command.
            //    ImportSite(filename, targeturl, haltOnWarning, haltOnFatalError, noFileCompression, includeUserSecurity,
            //               quiet, logFile, updateVersions);
            //    return;
            //}

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

            SetupImportObject(settings, !noFileCompression, filename, haltOnFatalError, haltOnWarning, includeUserSecurity, logFile, quiet, updateVersions, retainObjectIdentity, suppressAfterEvents);

            using (SPSite site = new SPSite(targeturl))
            {
                settings.SiteUrl = site.Url;
                Common.Lists.ExportList.ValidateUser(site);

                string dirName;
                Utilities.SplitUrl(Utilities.ConvertToServiceRelUrl(Utilities.GetServerRelUrlFromFullUrl(targeturl), site.ServerRelativeUrl), out dirName, out m_webName);
                m_webParentUrl = site.ServerRelativeUrl;
                if (!string.IsNullOrEmpty(dirName))
                {
                    if (!m_webParentUrl.EndsWith("/"))
                    {
                        m_webParentUrl = m_webParentUrl + "/";
                    }
                    m_webParentUrl = m_webParentUrl + dirName;
                }
                if (m_webName == null)
                {
                    m_webName = string.Empty;
                }
            }

            EventHandler<SPDeploymentEventArgs> handler = new EventHandler<SPDeploymentEventArgs>(OnSiteImportStarted);
            import.Started += handler;

            try
            {
                import.Run();
            }
            catch (SPException ex)
            {
                if (retainObjectIdentity && ex.Message.StartsWith("The Web site address ") && ex.Message.EndsWith(" is already in use."))
                {
                    throw new SPException(
                        "You cannot import the web because the source web still exists.  Either specify the \"-deletesource\" parameter or manually delete the source web and use the exported file.", ex);

                }
                else
                    throw;
            }
            finally
            {
                Console.WriteLine();
                Console.WriteLine("Log file generated: ");
                Console.WriteLine("\t{0}", settings.LogFilePath);
                Console.WriteLine();
            }
        }
        /// <summary>
        /// Sets up the import object.
        /// </summary>
        /// <param name="settings">The settings.</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> [includeusersecurity].</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="updateVersions">The update versions.</param>
        /// <param name="retainObjectIdentity">if set to <c>true</c> [retain object identity].</param>
        /// <param name="suppressAfterEvents">if set to <c>true</c> [suppress after events].</param>
        internal static void SetupImportObject(SPImportSettings settings, bool compressFile, string filename, bool haltOnFatalError, bool haltOnWarning, bool includeusersecurity, bool logFile, bool quiet, SPUpdateVersions updateVersions, bool retainObjectIdentity, bool suppressAfterEvents)
        {
            settings.CommandLineVerbose = !quiet;
            settings.HaltOnNonfatalError = haltOnFatalError;
            settings.HaltOnWarning = haltOnWarning;
            settings.FileCompression = compressFile;
            settings.SuppressAfterEvents = suppressAfterEvents;

            if (!compressFile)
            {
                if (string.IsNullOrEmpty(filename) || !Directory.Exists(filename))
                {
                    throw new SPException(SPResource.GetString("DirectoryNotFoundExceptionMessage", new object[] { filename }));
                }
            }
            else if (string.IsNullOrEmpty(filename) || !File.Exists(filename))
            {
                throw new SPException(SPResource.GetString("FileNotFoundExceptionMessage", new object[] { filename }));
            }

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

            if (logFile)
            {
                if (!compressFile)
                {
                    settings.LogFilePath = Path.Combine(settings.FileLocation, "import.log");
                }
                else
                    settings.LogFilePath = Path.Combine(settings.FileLocation, filename + ".import.log");
            }

            if (includeusersecurity)
            {
                settings.IncludeSecurity = SPIncludeSecurity.All;
                settings.UserInfoDateTime = SPImportUserInfoDateTimeOption.ImportAll;
            }
            settings.UpdateVersions = updateVersions;
            settings.RetainObjectIdentity = retainObjectIdentity;
        }
Ejemplo n.º 18
0
 public WizardImportSettings(SPImportSettings ImportSettings)
 {
     Settings = ImportSettings;
 }
Ejemplo n.º 19
0
        public void ImportToSite(
            [JSDoc("Provides the SPSite of the import target. Can be a SPSite instance a uri or a string url.")]
            object site,
            object fileLocation,
            object baseFileName,
            object logFilePath,
            object isDropFileLocation)
        {
            var importSettings = new SPImportSettings
            {
                SiteUrl              = SPBaristaContext.Current.Site.Url,
                IncludeSecurity      = Microsoft.SharePoint.Deployment.SPIncludeSecurity.All,
                RetainObjectIdentity = false,
                CommandLineVerbose   = true,
            };

            if (site != Null.Value && site != Undefined.Value)
            {
                if (site is SPSiteInstance)
                {
                    importSettings.SiteUrl = (site as SPSiteInstance).Site.Url;
                }
                else if (site is GuidInstance)
                {
                    var guid = (site as GuidInstance).Value;
                    using (var spSite = new SPSite(guid, SPBaristaContext.Current.Site.UserToken))
                    {
                        importSettings.SiteUrl = spSite.Url;
                    }
                }
                else if (site is UriInstance)
                {
                    var uri = (site as UriInstance).Uri;
                    using (var spSite = new SPSite(uri.ToString(), SPBaristaContext.Current.Site.UserToken))
                    {
                        importSettings.SiteUrl = spSite.Url;
                    }
                }
                else
                {
                    var siteUrl = TypeConverter.ToString(site);
                    using (var spSite = new SPSite(siteUrl, SPBaristaContext.Current.Site.UserToken))
                    {
                        importSettings.SiteUrl = spSite.Url;
                    }
                }
            }

            if (fileLocation != Null.Value && fileLocation != Undefined.Value)
            {
                var strFileLocation = TypeConverter.ToString(fileLocation);
                importSettings.FileLocation = strFileLocation;
            }

            if (baseFileName != Null.Value && baseFileName != Undefined.Value)
            {
                var strBaseFileName = TypeConverter.ToString(baseFileName);
                importSettings.BaseFileName = strBaseFileName;
            }

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

            var import = new SPImport {
                Settings = importSettings
            };

            if (isDropFileLocation != Null.Value && isDropFileLocation != Undefined.Value)
            {
                var bIsDropFileLocation = TypeConverter.ToBoolean(isDropFileLocation);
                if (bIsDropFileLocation)
                {
                    SPImportInstance.CopyFilesFromDropLocationToTempLocation(import, importSettings.FileLocation, importSettings.BaseFileName);
                }
            }

            import.Run();
        }
Ejemplo n.º 20
0
 public WizardImportSettings(SPImportSettings ImportSettings)
 {
     Settings = ImportSettings;
 }
        /// <summary>
        /// Performs the import.
        /// </summary>
        /// <param name="import">The import.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="logFile">if set to <c>true</c> [log file].</param>
        /// <param name="targetUrl">The Source URL.</param>
        internal void PerformImport(SPImport import, SPImportSettings settings, bool logFile, string targetUrl)
        {
            using (SPSite site = new SPSite(targetUrl))
            {
                ExportList.ValidateUser(site);

                using (SPWeb web = site.OpenWeb())
                {
                    settings.SiteUrl = site.Url;
                    settings.WebUrl = web.Url;
                }
            }
            import.ObjectImported += new EventHandler<SPObjectImportedEventArgs>(OnImported);

            try
            {
                import.Run();
            }
            finally
            {
                if (logFile)
                {
                    Console.WriteLine();
                    Console.WriteLine("Log file generated: ");
                    Console.WriteLine("\t{0}", settings.LogFilePath);
                    Console.WriteLine();
                }
            }
        }
        /// <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();
            }
        }
        public void PerformImport(bool compressFile, string filename, bool quiet, bool haltOnWarning, bool haltOnFatalError, bool includeusersecurity, bool logFile, bool retainObjectIdentity, bool copySecurity, bool suppressAfterEvents, SPUpdateVersions updateVersions)
        {
            SPImportSettings settings = new SPImportSettings();
            SPImport import = new SPImport(settings);

            StsAdm.OperationHelpers.ImportHelper.SetupImportObject(settings, 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, settings, 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 (includeusersecurity && !string.IsNullOrEmpty(m_sourceUrl) && copySecurity)
                {
                    using (SPSite sourceSite = new SPSite(m_sourceUrl))
                    using (SPWeb sourceWeb = sourceSite.OpenWeb())
                    {
                        SPList sourceList = Utilities.GetListFromViewUrl(sourceWeb, m_sourceUrl);

                        if (sourceList != null)
                        {
                            if (m_targetList != null)
                                Common.Lists.CopyListSecurity.CopySecurity(sourceList, m_targetList, m_targetWeb, true, quiet);
                        }
                    }
                }
            }
            finally
            {
                if (m_targetSite != null)
                    m_targetSite.Dispose();
                if (m_targetWeb != null)
                    m_targetWeb.Dispose();
            }
        }
Ejemplo n.º 24
0
        internal static WizardImportSettings CollectImportSettings(XmlTextReader importSettingsXml)
        {
            if (traceSwitchStatic.TraceVerbose)
            {
                traceStatic.TraceVerbose("CollectImportSettings: Entered CollectImportSettings().");
            }

            if (importSettingsXml.Name != "ImportSettings")
            {
                importSettingsXml.Read();
            }

            // create SPImportSettings object..
            SPImportSettings importSettings = new SPImportSettings();

            if (importSettingsXml.Name == "ImportSettings")
            {
                if (importSettingsXml.MoveToAttribute("SiteUrl"))
                {
                    importSettings.SiteUrl = importSettingsXml.Value;
                }
                if (importSettingsXml.MoveToAttribute("ImportWebUrl"))
                {
                    if (!string.IsNullOrEmpty(importSettingsXml.Value))
                    {
                        importSettings.WebUrl = importSettingsXml.Value;
                    }
                }
                if (importSettingsXml.MoveToAttribute("FileLocation"))
                {
                    importSettings.FileLocation = importSettingsXml.Value;
                }
                if (importSettingsXml.MoveToAttribute("BaseFileName"))
                {
                    importSettings.BaseFileName = importSettingsXml.Value;
                }
                if (importSettingsXml.MoveToAttribute("IncludeSecurity"))
                {
                    importSettings.IncludeSecurity = (SPIncludeSecurity)Enum.Parse(typeof(SPIncludeSecurity), importSettingsXml.Value);
                }
                if (importSettingsXml.MoveToAttribute("VersionOptions"))
                {
                    importSettings.UpdateVersions = (SPUpdateVersions)Enum.Parse(typeof(SPUpdateVersions), importSettingsXml.Value);
                }
                if (importSettingsXml.MoveToAttribute("RetainObjectIdentity"))
                {
                    importSettings.RetainObjectIdentity = bool.Parse(importSettingsXml.Value);
                }
                if (importSettingsXml.MoveToAttribute("FileCompression"))
                {
                    importSettings.FileCompression = bool.Parse(importSettingsXml.Value);
                }
                if (importSettingsXml.MoveToAttribute("UserInfoUpdate"))
                {
                    importSettings.UserInfoDateTime = (SPImportUserInfoDateTimeOption)Enum.Parse(typeof(SPImportUserInfoDateTimeOption), importSettingsXml.Value);
                }
            }

            importSettingsXml.Close();

            // set other properties which aren't tied to values in XML..
            importSettings.LogFilePath = string.Format("{0}\\{1}.Import.log",
                                                       importSettings.FileLocation, importSettings.BaseFileName);

            if (traceSwitchStatic.TraceInfo)
            {
                traceStatic.TraceInfo("CollectImportSettings: Using site URL '{0}'.", importSettings.SiteUrl);
                traceStatic.TraceInfo("CollectImportSettings: Using web URL '{0}'.", importSettings.WebUrl);
                traceStatic.TraceInfo("CollectImportSettings: File location = '{0}'.", importSettings.FileLocation);
                traceStatic.TraceInfo("CollectImportSettings: Base filename = '{0}'.", importSettings.BaseFileName);
                traceStatic.TraceInfo("CollectImportSettings: Update versions = '{0}'.", importSettings.UpdateVersions);
                traceStatic.TraceInfo("CollectImportSettings: Log file path = '{0}'.", importSettings.LogFilePath);
                traceStatic.TraceInfo("CollectImportSettings: Include security = '{0}'.", importSettings.IncludeSecurity);
                traceStatic.TraceInfo("CollectImportSettings: Retain object identity = '{0}'.", importSettings.RetainObjectIdentity);
            }

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

            WizardImportSettings wiSettings = new WizardImportSettings(importSettings);

            return(wiSettings);
        }
 protected override void InternalProcessRecord()
 {
     string path = base.Path;
     if (!base.NoFileCompression.IsPresent)
     {
         if (string.IsNullOrEmpty(path) || !File.Exists(path))
         {
             throw new SPException(SPResource.GetString("FileNotFoundExceptionMessage", new object[] { path }));
         }
     }
     else if (string.IsNullOrEmpty(path) || !Directory.Exists(path))
     {
         throw new SPException(SPResource.GetString("DirectoryNotFoundExceptionMessage", new object[] { path }));
     }
     string url = this.Identity.Read().Url;
     if (base.ShouldProcess(string.Format("ShouldProcessImportWeb,{0},{1}", url, base.Path )))
     {
         SPImportSettings settings = new SPImportSettings();
         SPImport import = new SPImport(settings);
         base.SetDeploymentSettings(settings);
         if (base.IncludeUserSecurity.IsPresent)
         {
             settings.IncludeSecurity = SPIncludeSecurity.All;
             settings.UserInfoDateTime = SPImportUserInfoDateTimeOption.ImportAll;
         }
         settings.SuppressAfterEvents = SuppressAfterEvents.IsPresent;
         settings.UpdateVersions = this.UpdateVersions;
         char[] trimChars = new char[] { '/' };
         if (url[url.Length - 1] == '/')
         {
             url = url.TrimEnd(trimChars);
         }
         settings.RetainObjectIdentity = RetainObjectIdentity.IsPresent;
         settings.SiteUrl = url;
         using (SPSite site = new SPSite(url))
         {
             string str5;
             Utilities.SplitUrl(Utilities.ConvertToServiceRelUrl(Utilities.GetServerRelUrlFromFullUrl(url), site.ServerRelativeUrl), out str5, out this.m_webName);
             this.m_webParentUrl = site.ServerRelativeUrl;
             if (!string.IsNullOrEmpty(str5))
             {
                 if (!this.m_webParentUrl.EndsWith("/"))
                 {
                     this.m_webParentUrl = this.m_webParentUrl + "/";
                 }
                 this.m_webParentUrl = this.m_webParentUrl + str5;
             }
         }
         if (this.m_webName == null)
         {
             this.m_webName = string.Empty;
         }
         EventHandler<SPDeploymentEventArgs> handler = new EventHandler<SPDeploymentEventArgs>(this.OnStarted);
         import.Started += handler;
         try
         {
             import.Run();
         }
         finally
         {
             if (!base.NoLogFile.IsPresent)
             {
                 Console.WriteLine();
                 Console.WriteLine(SPResource.GetString("ExportOperationLogFile", new object[0]));
                 Console.WriteLine("\t{0}", settings.LogFilePath);
                 Console.WriteLine();
             }
         }
     }
 }
Ejemplo n.º 26
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();
                }
            }
        }