public override void Execute(Guid targetInstanceId) { var export = new SPExport(SetUpExportSettings()); var import = new SPImport(SetUpImportSettings()); export.Run(); import.Run(); }
/// <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(); } } }
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; // } }
/// <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); }
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); }
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> /// 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(); } }
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(); }
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; }
/// <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 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(); } } } }
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); } }
public void Run() { //SPExportInstance.CopyFilesToDropLocation(m_export, m_dropLocation); m_import.Run(); }
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); }); }
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(); } } } }
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; // } }