Exemplo 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();
                }
            }
        }
 public override void Execute(Guid targetInstanceId)
 {
     var export = new SPExport(SetUpExportSettings());
     var import = new SPImport(SetUpImportSettings());
     export.Run();
     import.Run();
 }
Exemplo n.º 3
0
        private void BackupMenuItem_Click(object sender, EventArgs e)
        {
            //SaveFileDialog fileDialog = new SaveFileDialog();

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

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

            string siteurl = site.Url;

            SPExportSettings exportSettings = new SPExportSettings();

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

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

            //exportSettings.ExportMethod = SPExportMethodType.ExportAll;

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

            SPExport export = new SPExport(exportSettings);

            export.Run();


            SPImportSettings importSettings = new SPImportSettings();

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

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

            SPImport import = new SPImport();

            import.Run();


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

            Cursor.Current = Cursors.Default;
//            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Called when [imported].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="eventArgs">The <see cref="Microsoft.SharePoint.Deployment.SPObjectImportedEventArgs"/> instance containing the event data.</param>
        public void OnImported(object sender, SPObjectImportedEventArgs eventArgs)
        {
            if (m_targetList == null && eventArgs.Type == SPDeploymentObjectType.List)
            {
                // Get the list for later processing.
                m_targetList = m_targetWeb.GetList(eventArgs.TargetUrl);
            }

            if (!m_retargetLinks)
            {
                return;
            }

            if (eventArgs.Type != SPDeploymentObjectType.ListItem)
            {
                return;
            }

            SPImport import = sender as SPImport;

            if (import == null)
            {
                return;
            }

            try
            {
                string url = eventArgs.SourceUrl; // This is not fully qualified so we need the user specified url for the site.
                using (SPSite site = new SPSite(m_sourceUrl))
                    using (SPWeb web = site.OpenWeb(url, false))
                    {
                        string     targetUrl = m_targetSite.MakeFullUrl(eventArgs.TargetUrl);
                        SPListItem li        = web.GetListItem(url);
                        int        count     = li.BackwardLinks.Count;
                        for (int i = count - 1; i >= 0; i--)
                        {
                            SPLink link = li.BackwardLinks[i];
                            using (SPWeb rweb = site.OpenWeb(link.ServerRelativeUrl, false))
                            {
                                object o = rweb.GetObject(link.ServerRelativeUrl);
                                if (o is SPFile)
                                {
                                    SPFile f = o as SPFile;
                                    f.ReplaceLink(eventArgs.SourceUrl, targetUrl);
                                }
                                if (o is SPListItem)
                                {
                                    SPListItem l = o as SPListItem;
                                    l.ReplaceLink(eventArgs.SourceUrl, targetUrl);
                                }
                            }
                        }
                    }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Links could not be retargeted for " + eventArgs.SourceUrl + "\r\n" + ex.Message);
            }
        }
        public SPImportInstance(ObjectInstance prototype, SPImport import)
            : this(prototype)
        {
            if (import == null)
            {
                throw new ArgumentNullException("import");
            }

            m_import = import;
        }
Exemplo 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);
        }
Exemplo n.º 7
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();
                }
            }
        }
        public static void CopyFilesFromDropLocationToTempLocation(SPImport import, string dropLocation, string baseFileName)
        {
            //If a drop location is specified, copy the files to the target location.
            if (dropLocation.IsNullOrWhiteSpace())
            {
                return;
            }

            SPSite   dropSite;
            SPWeb    dropWeb;
            SPFolder dropFolder;

            if (!SPHelper.TryGetSPFolder(dropLocation, out dropSite, out dropWeb, out dropFolder))
            {
                return;
            }

            var tempPath = Path.GetTempPath();

            try
            {
                foreach (var fileToCopy in dropFolder.Files.OfType <SPFile>().Where(fn => fn.Name.StartsWith(baseFileName)))
                {
                    using (var fs = File.Create(Path.Combine(tempPath, fileToCopy.Name)))
                    {
                        using (var str = fileToCopy.OpenBinaryStream(SPOpenBinaryOptions.None))
                        {
                            str.CopyTo(fs);
                        }
                        fs.Flush();
                    }
                }
                import.Settings.FileLocation = tempPath;
            }
            finally
            {
                if (dropSite != null)
                {
                    dropSite.Dispose();
                }

                if (dropWeb != null)
                {
                    dropWeb.Dispose();
                }
            }
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        public void Import(
            [JSDoc("An object that contains import settings properties or an instance of SPImportSettings")] object
            importSettings,
            [JSDoc("The target drop location from where the files should be copied from or null to use files on the files system.")]
            object dropLocation)
        {
            var import = new SPImport();

            if (importSettings is SPImportSettingsInstance)
            {
                import.Settings = (importSettings as SPImportSettingsInstance).SPImportSettings;
            }
            else if (importSettings is ObjectInstance)
            {
                var settings = JurassicHelper.Coerce <SPImportSettingsInstance>(Engine, importSettings as ObjectInstance);
                import.Settings = settings.SPImportSettings;
            }
            else
            {
                throw new JavaScriptException(Engine, "Error", "Expected the first argument to be an import settings object.");
            }

            import.Run();
        }
        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;
            }
        }
        /// <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();
            }
        }
Exemplo n.º 13
0
        public ImportOperationResult RunImport()
        {
            if (traceSwitch.TraceVerbose)
            {
                trace.TraceVerbose("RunImport: Entered RunImport().");
            }

            ImportOperationResult importResult;
            SPChangeToken startChangeToken = null;
            SPChangeToken endChangeToken = null;
            string destinationRootWebUrl = null;

            if (traceSwitch.TraceInfo)
            {
                trace.TraceInfo("RunImport: Initialising SPSite object with URL '{0}'.",
                    ImportSettings.SiteUrl);
            }

            using (SPSite destinationSite = new SPSite(ImportSettings.SiteUrl))
            {
                // Get the change token from the destination site..
                startChangeToken = destinationSite.CurrentChangeToken;

                if (traceSwitch.TraceInfo)
                {
                    trace.TraceInfo("RunImport: StartChangeToken is '{0}'.",
                        startChangeToken.ToString());
                }

                // Save the root Web URL for future use..
                destinationRootWebUrl = destinationSite.RootWeb.ServerRelativeUrl;

                using (SPImport import = new SPImport(ImportSettings))
                {
                    import.Started += new EventHandler<SPDeploymentEventArgs>(import_Started);
                    import.ObjectImported += new EventHandler<SPObjectImportedEventArgs>(import_ObjectImported);
                    import.ProgressUpdated += new EventHandler<SPDeploymentEventArgs>(import_ProgressUpdated);
                    import.Completed += new EventHandler<SPDeploymentEventArgs>(import_Completed);

                    if (traceSwitch.TraceInfo)
                    {
                        trace.TraceInfo("RunImport: Wired event handlers, about to call Run()..");
                    }

                    // initialise to default..
                    importResult = new ImportOperationResult(ResultType.Failure);

                    try
                    {
                        import.Run();

                        if (traceSwitch.TraceInfo)
                        {
                            trace.TraceInfo("RunImport: Import completed successfully.");
                        }

                        importResult = new ImportOperationResult(ResultType.Success);
                    }
                    catch (Exception e)
                    {
                        if (traceSwitch.TraceError)
                        {
                            trace.TraceError("RunImport: Exception caught whilst running import: '{0}'.", e);
                        }

                        importResult = new ImportOperationResult(ResultType.Failure, e.ToString());
                    }

                    // Get the change token from the destination site AFTER import..
                    endChangeToken = destinationSite.CurrentChangeToken;

                    if (traceSwitch.TraceInfo)
                    {
                        trace.TraceInfo("RunImport: End change token is '{0}', attempting to set publish schedule.", 
                            endChangeToken.ToString());
                    }

                    attemptPublishScheduleSet(startChangeToken, endChangeToken, destinationSite);
                }
            }

            if (traceSwitch.TraceVerbose)
            {
                trace.TraceVerbose("RunImport: Exiting RunImport().");
            }

            return importResult;
        }
        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);
            }
        }
        /// <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();
            }
        }
Exemplo n.º 17
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();
        }
Exemplo n.º 18
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;
            //            }
        }
        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);

            });
        }
Exemplo n.º 20
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();
                }
            }
        }
        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();
            }
        }
        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();
                    }
                }
            }
        }
Exemplo n.º 23
0
        public ImportOperationResult RunImport()
        {
            if (traceSwitch.TraceVerbose)
            {
                trace.TraceVerbose("RunImport: Entered RunImport().");
            }

            ImportOperationResult importResult;
            SPChangeToken         startChangeToken = null;
            SPChangeToken         endChangeToken   = null;
            string destinationRootWebUrl           = null;

            if (traceSwitch.TraceInfo)
            {
                trace.TraceInfo("RunImport: Initialising SPSite object with URL '{0}'.",
                                ImportSettings.SiteUrl);
            }

            using (SPSite destinationSite = new SPSite(ImportSettings.SiteUrl))
            {
                // Get the change token from the destination site..
                startChangeToken = destinationSite.CurrentChangeToken;

                if (traceSwitch.TraceInfo)
                {
                    trace.TraceInfo("RunImport: StartChangeToken is '{0}'.",
                                    startChangeToken.ToString());
                }

                // Save the root Web URL for future use..
                destinationRootWebUrl = destinationSite.RootWeb.ServerRelativeUrl;

                using (SPImport import = new SPImport(ImportSettings))
                {
                    import.Started         += new EventHandler <SPDeploymentEventArgs>(import_Started);
                    import.ObjectImported  += new EventHandler <SPObjectImportedEventArgs>(import_ObjectImported);
                    import.ProgressUpdated += new EventHandler <SPDeploymentEventArgs>(import_ProgressUpdated);
                    import.Completed       += new EventHandler <SPDeploymentEventArgs>(import_Completed);

                    if (traceSwitch.TraceInfo)
                    {
                        trace.TraceInfo("RunImport: Wired event handlers, about to call Run()..");
                    }

                    // initialise to default..
                    importResult = new ImportOperationResult(ResultType.Failure);

                    try
                    {
                        import.Run();

                        if (traceSwitch.TraceInfo)
                        {
                            trace.TraceInfo("RunImport: Import completed successfully.");
                        }

                        importResult = new ImportOperationResult(ResultType.Success);
                    }
                    catch (Exception e)
                    {
                        if (traceSwitch.TraceError)
                        {
                            trace.TraceError("RunImport: Exception caught whilst running import: '{0}'.", e);
                        }

                        importResult = new ImportOperationResult(ResultType.Failure, e.ToString());
                    }

                    // Get the change token from the destination site AFTER import..
                    endChangeToken = destinationSite.CurrentChangeToken;

                    if (traceSwitch.TraceInfo)
                    {
                        trace.TraceInfo("RunImport: End change token is '{0}', attempting to set publish schedule.",
                                        endChangeToken.ToString());
                    }

                    attemptPublishScheduleSet(startChangeToken, endChangeToken, destinationSite);
                }
            }

            if (traceSwitch.TraceVerbose)
            {
                trace.TraceVerbose("RunImport: Exiting RunImport().");
            }

            return(importResult);
        }
 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>
        /// 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();
                }
            }
        }