home screen

Search



Number Of Result : 0

Result :


Wednesday, March 31, 2010

Export and Import Site in SharePoint


static void Main(string[] args)
{

try
{
string newUrl = "http://abc.com/sites/Team123";
string oldUrl = "http://abc.com/sites/Team";
ExportImport(newUrl, oldUrl);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.WriteLine("Done");
}



private static void ExportImport(string sourceUrl, string destinationUrl)
{
string fileName = Export(sourceUrl);
Import(destinationUrl, fileName);
}




private static string Export(string siteURL)
{
Microsoft.SharePoint.Deployment.SPExportSettings exportSettings =
new Microsoft.SharePoint.Deployment.SPExportSettings();
exportSettings.AutoGenerateDataFileName = true;
exportSettings.ExportMethod =
Microsoft.SharePoint.Deployment.SPExportMethodType.ExportAll;
exportSettings.SiteUrl = siteURL;
exportSettings.IncludeSecurity =
Microsoft.SharePoint.Deployment.SPIncludeSecurity.All;
exportSettings.IncludeVersions =
Microsoft.SharePoint.Deployment.SPIncludeVersions.All;
Microsoft.SharePoint.Deployment.SPExport export =
new Microsoft.SharePoint.Deployment.SPExport(exportSettings);
export.Run();

return exportSettings.FileLocation + "\\" + exportSettings.BaseFileName;
}




private static void Import(string siteURL, string fileToImport)
{
Microsoft.SharePoint.Deployment.SPImportSettings importSettings =
new Microsoft.SharePoint.Deployment.SPImportSettings();

importSettings.BaseFileName = System.IO.Path.GetFileName(fileToImport);
importSettings.FileLocation = System.IO.Path.GetDirectoryName(fileToImport);
importSettings.SiteUrl = siteURL;
importSettings.RetainObjectIdentity = true;
importSettings.IncludeSecurity =
Microsoft.SharePoint.Deployment.SPIncludeSecurity.All;
importSettings.UpdateVersions =
Microsoft.SharePoint.Deployment.SPUpdateVersions.Append;
importSettings.UserInfoDateTime =
Microsoft.SharePoint.Deployment.SPImportUserInfoDateTimeOption.ImportAll;
Microsoft.SharePoint.Deployment.SPImport import =
new Microsoft.SharePoint.Deployment.SPImport(importSettings);
import.Run();
}

No comments: