How to: Migrate a Web site from one location to another

The following procedures provide an example of how to use the Content Migration object model to move a Windows SharePoint Services Web site from one location to another.

To export the Web site

  1. Add the following using directives to your project.

    C#
    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Administration;
    using Microsoft.SharePoint.Deployment;
  2. Create an SPExportSettings object to specify settings for the export operation.

    C#
    SPExportSettings exportSettings = new SPExportSettings();
  3. Indicate the source URL.

    C#
    exportSettings.SiteUrl = "http://webname";
  4. Indicate the type of export you want to do, for example, you can export all of a Web site's contents, or only incremental changes. In this example, we are exporting all of the data.

    C#
    exportSettings.ExportMethod = SPExportMethodType.ExportAll;
  5. Identify a location for the output file (the *.cmp file, which is also called a Content Migration package). The following statements create a file at c:\exportfile.cmp.

    C#
    exportSettings.BaseFileName = "exportfile";
    exportSettings.FileLocation = @"c:\";
  6. Determine which metadata you want to include when exporting the data. For example, do you want to include versioning information? Security information?

    For this example, we are using all the default values—only the last major version of each item is migrated. No user or group information is migrated.

  7. Create a new instance of the SPExport class, pass it the SPExportSettings object, and run it.

    C#
    SPExport export = new SPExport(exportSettings);
    Export.Run();

To import the Web site

  1. Create an instance of the SPImportSettings class to specify settings for the import operation.

    C#
    SPImportSettings importSettings = new SPImportSettings;
  2. Specify the location of the Content Migration package that was created in step 3 of the export.

    C#
    importSettings.BaseFileName = "exportfile";
    importSettings.FileLocation = @"c:\";
  3. Specify the destination location where you want to create the Web site.

    C#
    importSettings.SiteUrl = "http://newweb";
  4. Determine the metadata that you want to include when importing the data, for example, how to handle versioning, author/editor information for the files, and whether to retain GUIDs.

    We again use the default values—new versions are appended, and no author/editor information or GUIDs are imported.

  5. Create a new instance of the SPImport class, pass it the SPImportSettings object, and run it.

    C#
    SPImport import = new SPImport(importSettings);
    Import.Run();

See Also

Tags :


Community Content

Alhambra Eidos Desarrollo
Errors in code source

See the following reference

http://geeks.ms/blogs/gvelez/archive/2007/01/29/cuantos-errores-se-pueden-cometer-en-15-l-neas-de-c-digo.aspx

Tags :

Hector Mike
Exporting site collection documents (winforms app)

Create a Windows forms application. Rename Form1 as MainForm. Drop three text boxes and three combo boxes named txtSiteUrl, txtBaseFileName, txtFileLocation, cboExportMethodType, cboIncludeVersions, and cboDeployObjType, respectively, on the form (along with some labels for them). Drop a button named btnExport on the form. Double-click the button to create a stub for the click event procedure. Add the following code to the constructor and button click event procedures:

    public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
            this.cboExportMethodType.DataSource = Enum.GetValues(typeof(SPExportMethodType));
this.cboIncludeVersions.DataSource = Enum.GetValues(typeof(SPIncludeVersions));
this.cboDeployObjType.DataSource = Enum.GetValues(typeof(SPDeploymentObjectType));
}
        private void btnExport_Click(object sender, EventArgs e)
{
SPExportSettings xs = new SPExportSettings();
            xs.SiteUrl = this.txtSiteUrl.Text; // @"http://SomeServer:SomePort/";
xs.FileCompression = true;
xs.BaseFileName = this.txtBaseFileName.Text; // "MyExportFileName";
xs.FileLocation = @"c:\temp";
xs.OverwriteExistingDataFile = true;
            xs.ExportMethod = (SPExportMethodType)(Enum.Parse(typeof(SPExportMethodType), this.cboExportMethodType.SelectedValue.ToString()));
xs.IncludeVersions = (SPIncludeVersions)(Enum.Parse(typeof(SPIncludeVersions), this.cboIncludeVersions.SelectedValue.ToString()));
            SPExportObject xo = new SPExportObject();
            if (this.txtSiteUrl.Text.Substring(this.txtSiteUrl.Text.Length - 1, 1) != "/")
this.txtSiteUrl.Text += "/";
            xo.Url = this.txtSiteUrl.Text + "SiteCollectionDocuments";
xo.Type = (SPDeploymentObjectType)(Enum.Parse(typeof(SPDeploymentObjectType), this.cboDeployObjType.SelectedValue.ToString()));
xo.ExcludeChildren = false;
xo.IncludeDescendants = SPIncludeDescendants.All;
xs.ExportObjects.Add(xo);
            SPExport xe = new SPExport(xs);
xe.Run();
}
}

Run the application. (The combo boxes are bound to the enums, so you do not have to do anything to see your choices.) Choose ExportAll from the export method type combo, All from the include versions combo, and Folder or List from the deployment object type combo. An output file will be created (.cmp file). I noticed that in order to import the data on the other end, it is necessary to specify the .cmp file extension. For example:

    SPImportSettings mx = new SPImportSettings();
mx.SiteUrl = @"http://OtherServer:SomePort/";
mx.BaseFileName = "MyExportFileName.cmp";
mx.FileLocation = @"c:\temp";
mx.FileCompression = true;
SPImport me = new SPImport(mx);
me.Run();
Tags :

Page view tracker