0

这是我当前的设置:

  • SharePoint 2007 (MOSS Enterprise) 框中的一个网站集(总大小为 32 GB)
  • 一个包含许多子网站的主网站(如果重要的话,主要是从团队网站模板创建的),它是框中的一个网站集的一部分

我正在尝试做的*:

**如果有更好的顺序或以下方法,我愿意更改它*

  1. 在同一个 SP 实例上创建一个具有主要默认站点的新站点集(这已完成,在 SP 对象模型中很容易做到)
  2. 将 rootweb (a) 移动为新位置的子站点,在主站点下

当前结构:

rootweb (a)
          \
          many sub sites (sub a)

新结构应该是什么样子:

newrootweb(b)
       \
        oldrootweb (a)
            \
             old many sub sites (sub a)

这是我第 2 步的代码:

注意: * SharePoint.Administration 下的对象模型中的 SPImport 是此处使用的内容 * 此代码当前在触发错误事件处理程序时出错,并显示“对象引用不是对象的实例”

using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Deployment;

public static bool FullImport(string baseFilename, bool CommandLineVerbose, bool bfileCompression, string fileLocation, bool HaltOnNonfatalError,
           bool HaltOnWarning, bool IgnoreWebParts, string LogFilePath, string destinationUrl)
        {
            #region my try at import

            string message = string.Empty;
            bool bSuccess = false;
            try
            {
                SPImportSettings settings = new SPImportSettings();
                settings.BaseFileName = baseFilename;
                settings.CommandLineVerbose = CommandLineVerbose;
                settings.FileCompression = bfileCompression;
                settings.FileLocation = fileLocation;
                settings.HaltOnNonfatalError = HaltOnNonfatalError;
                settings.HaltOnWarning = HaltOnWarning;
                settings.IgnoreWebParts = IgnoreWebParts;
                settings.IncludeSecurity = SPIncludeSecurity.All;
                settings.LogFilePath = fileLocation;
                settings.WebUrl = destinationUrl;
                settings.SuppressAfterEvents = true;
                settings.UpdateVersions = SPUpdateVersions.Append;
                settings.UserInfoDateTime = SPImportUserInfoDateTimeOption.ImportAll;

                SPImport import = new SPImport(settings);

                import.Started += delegate(System.Object o, SPDeploymentEventArgs e)
                {
                    //started
                    message = "Current Status: " + e.Status.ToString() + " " + e.ObjectsProcessed.ToString() + " of " + e.ObjectsTotal + " objects processed thus far.";
                    message = e.Status.ToString();
                };
                import.Completed += delegate(System.Object o, SPDeploymentEventArgs e)
                {
                    //done
                    message = "Current Status: " + e.Status.ToString() + " " + e.ObjectsProcessed.ToString() + " of " + e.ObjectsTotal + " objects processed.";
                };
                import.Error += delegate(System.Object o, SPDeploymentErrorEventArgs e)
                {
                    //broken
                    message = "Error Message: " + e.ErrorMessage.ToString() + " Error Type: " + e.ErrorType + " Error Recommendation: " + e.Recommendation
                        + " Deployment Object: " + e.DeploymentObject.ToString();
                    System.Console.WriteLine("Error");
                };
                import.ProgressUpdated += delegate(System.Object o, SPDeploymentEventArgs e)
                {
                    //something happened
                    message = "Current Status: " + e.Status.ToString() + " " + e.ObjectsProcessed.ToString() + " of " + e.ObjectsTotal + " objects processed thus far.";
                };

                import.Run();

                bSuccess = true;
            }
            catch (Exception ex)
            {
                bSuccess = false;
                message = string.Format("Error: The site collection '{0}' could not be imported. The message was '{1}'. And the stacktrace was '{2}'", destinationUrl, ex.Message, ex.StackTrace);
            }

            #endregion

            return bSuccess;
        }

下面是调用上述方法的代码:

[TestMethod]
public void MOSS07_ObjectModel_ImportSiteCollection()
{
    bool bSuccess = ObjectModelManager.MOSS07.Deployment.SiteCollection.FullImport("SiteCollBAckup.cmp", true, true, @"C:\SPBACKUP\SPExports", false, false, false, @"C:\SPBACKUP\SPExports", "http://spinstancename/TestImport");
    Assert.IsTrue(bSuccess);
}
4

1 回答 1

0

您是否尝试过使用Codeplex中的SharePoint 内容部署向导,而不是尝试编写代码?
导出当前层次结构,并使用此工具将其导入新位置。

问候,米

于 2010-05-04T13:57:03.013 回答