SharePoint 2007对象模型:如何创建新的网站集,将原始主网站移动为新网站集的子网站?

时间:2010-05-04 13:37:09

标签: sharepoint sharepoint-2007 object-model

这是我目前的设置:

  • SharePoint 2007(MOSS企业版)框上的一个网站集(总大小为32 GB)
  • 一个主站点,其中包含许多子站点(主要是从团队站点模板创建的,如果这很重要),它们是框中一个站点集合的一部分

我正在尝试做什么*:

**如果有更好的订单或以下方法,我愿意改变它*

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

    目前的结构:

    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);
    }
    

1 个答案:

答案 0 :(得分:0)

您是否尝试使用Codeplex中的SharePoint Content Deployment Wizard而不是尝试对其进行编码? 导出当前层次结构,并使用此工具将其导入新位置。

此致 中号