Example 1 - Export a site
The first example shows you how to export a site to a file. The site exported in my sample is a subsite of a "Collaboration Portal" top level site. This is a site called “ContentDeploymentTest” and is has relative url “cdt”. The first step is to create and setup the SPExportObject. By setting the “Type” property of this object, you determine what content you are going to export. At this stage, the SDK is not very clear on what all options mean, but most values are pretty clear:
- File
- Folder
- List
- ListItem
- Site
- Web
- All
- Content
- None
The last step is to create an SPExport object. This takes the SPExportSettings object we just created as a parameter for the constructor. After doing this we call the Run() method and we are ready to test our export!
string sourceUrl = "http://office2007/cdt";
// Create the export object
SPExportObject exportSite = new SPExportObject();
exportSite.Type = SPDeploymentObjectType.Web;
exportSite.Url = sourceUrl;
exportSite.ExcludeChildren = false;
exportSite.IncludeDescendants = SPIncludeDescendants.All;
// Create the export settings
SPExportSettings settings = new SPExportSettings(
new Uri("http://office2007"), @"c:\ExportWebs", "SPExportTest.cab");
settings.ExportObjects.Add(exportSite);
settings.LogFilePath = @"c:\ExportWebs.log";
settings.FileCompression = true;
// Create the export object and run the export
SPExport export = new SPExport(settings);
export.Run();
This is slightly different from a Personal Web Package that you can create by using SharePoint Designer. If you export a site to a Personal Web Package, you also end up with a cab file (with extension FWP). This cab file has 1 xml file called manifest.xml. Apart from that you will see a lot of ASPX files and all the documents you uploaded. All files are named like “”file0002.aspx””, and the manifest file contains the index.
Example 2 - Import a site
Example 1 resulted in a cab file with a dump of one of my sites. Importing the into another site collection is very easy. The only thing that you have to take care of is making sure that there is a site with the correct url in your site collection. In my example I had to create a site with url “cdt” in my site collection (at url http://office2007:90). The reason for this manual step is the fact that I decided to export a subsite of my top level site, instead of exporting the whole top level site.
This process is very easy. First you setup an SPImportSettings object and point that to the destination site collection and to the location of the CAB file. After that you setup a SPImport object and call the Run method.
string destinationUrl = "http://office2007:90";
// Create the import settings
SPImportSettings settings = new SPImportSettings(
new Uri(destinationUrl), @"c:\ExportWebs", "SPExportTest.cab");
settings.LogFilePath = @"c:\ImportWebs.log";
settings.FileCompression = true;
// Create the import object and run the import
SPImport import = new SPImport(settings);
import.Run();
The next post will show how you can automate the setup of content deployment, that uses the same objects as I just discussed here.
No comments:
Post a Comment