private static string Export(string siteURL, string fileToExport)
{
SPExportSettings exportSettings = new SPExportSettings();
exportSettings.AutoGenerateDataFileName = true;
exportSettings.ExportMethod = SPExportMethodType.ExportAll;
exportSettings.SiteUrl = siteURL;
exportSettings.IncludeSecurity = SPIncludeSecurity.None;
exportSettings.IncludeVersions = SPIncludeVersions.CurrentVersion;
exportSettings.CommandLineVerbose = true;
exportSettings.FileLocation = fileToExport;
SPExportObject exportObject = new SPExportObject();
exportObject.ExcludeChildren = false;
exportObject.Type = SPDeploymentObjectType.Web;
using (SPSite site = new SPSite(siteURL))
{
using (SPWeb web = site.OpenWeb(siteURL.Substring(site.Url.Length, siteURL.Length - site.Url.Length)))
{
exportObject.Id = web.ID;
}
}
exportObject.IncludeDescendants = SPIncludeDescendants.All;
exportSettings.ExportObjects.Add(exportObject);
SPExport export = new SPExport(exportSettings);
export.Run();
return exportSettings.FileLocation + "\\" + exportSettings.BaseFileName;
}
private static void Import(string siteURL, string fileToImport)
{
SPImportSettings importSettings = new SPImportSettings();
importSettings.BaseFileName = System.IO.Path.GetFileName(fileToImport);
importSettings.FileLocation = System.IO.Path.GetDirectoryName(fileToImport);
importSettings.SiteUrl = siteURL;
importSettings.RetainObjectIdentity = false;
importSettings.IncludeSecurity = SPIncludeSecurity.None;
importSettings.UpdateVersions = SPUpdateVersions.Ignore;
importSettings.UserInfoDateTime = SPImportUserInfoDateTimeOption.None;
importSettings.SuppressAfterEvents = true;
importSettings.CommandLineVerbose = true;
SPImport import = new SPImport(importSettings);
import.Run();
}
No comments:
Post a Comment