Export Import Page

Export Page

One problem with STSADM tool is it cannot export List Item (like Publishing Pages…)  , It’s better to do export using object model and then import in production environment.

Options to export are :-
SPDeploymentObjectType.File              
SPDeploymentObjectType.Invalid
SPDeploymentObjectType.Folder
SPDeploymentObjectType.List
SPDeploymentObjectType.ListItem;
SPDeploymentObjectType.Site
SPDeploymentObjectType.Web

SPSite site = new SPSite(SiteName);
SPWeb web = site.OpenWeb();
SPList list = web.Lists[“Pages”];
SPExportObject exportObject = new SPExportObject();
SPListItem listItem = null;
listItem = list.Items[i];
exportObject.Id = listItem.UniqueId;
exportObject.Type =SPDeploymentObjectType.ListItem;

SPExportSettings exportSettings = new SPExportSettings();
SPExportSettings settings = new SPExportSettings();
exportSettings.SiteUrl = SiteName;
exportSettings.FileLocation =@”E:\WorkArea\XML_XSL\“;
exportSettings.BaseFileName =”SITE1.cmp”;
exportSettings.ExportMethod =SPExportMethodType.ExportAll; 

exportSettings.AutoGenerateDataFileName =true;
exportSettings.ExportObjects.Add(exportObject)

exportSettings.IncludeSecurity =SPIncludeSecurity.All;
exportSettings.IncludeVersions =SPIncludeVersions.All;
SPExport export = new SPExport(exportSettings);
export.Run();
string exportFileLocation = exportSettings.FileLocation + “\\” + exportSettings.BaseFileName;
 
Import Page

string targetListURL = “http://devsp:5001/Pages/“;
SPImportSettings settings = new SPImportSettings();
settings.SiteUrl = targetListURL;
settings.BaseFileName = “SITE1.cmp”;
settings.FileLocation = Path;
settings.FileCompression = true;
settings.IgnoreWebParts = false;
settings.IncludeSecurity = SPIncludeSecurity.All;
settings.RetainObjectIdentity = false;
settings.UpdateVersions = SPUpdateVersions.Append;
settings.UserInfoDateTime = SPImportUserInfoDateTimeOption.ImportAll;
settings.WebUrl = targetListURL;
settings.CommandLineVerbose = true;
settings.LogFilePath = @”E:\WorkArea\XML_XSL\bkp\import.log”;settings.Validate();
SPImport import = new SPImport(settings);

import.Run();

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s