views:

153

answers:

1

Here's my current setup:

  • one site collection on a SharePoint 2007 (MOSS Enterprise) box (32 GB total in size)
  • one main site with many subsites (mostly created from the team site template, if that matters) that is part of the one site collection on the box

What I'm trying to do*:

*If there is a better order, or method for the following, I'm open to changing it

  1. Create a new site collection, with a main default site, on same SP instance (this is done, easy to do in SP Object Model)
  2. Move rootweb (a) to be a subsite in the new location, under the main site

Current structure:

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

What new structure should look like:

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

Here's my code for step #2:

Notes: * SPImport in the object model under SharePoint.Administration, is what is being used here * This code currently errors out with "Object reference not an instance of an object", when it fires the error event handler

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

Here is the code calling the above method:

[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);
}
A: 

Hi there.

Instead of trying to code this up, have you tried to use the SharePoint Content Deployment Wizard from Codeplex?
Export your current hierarchy, and import it to the new place using this tool.

Regards, M

Magnus Johansson
Thank you for your answer. I'm aware of this tool, and I may have to give it a try, if doing it programmatically won't work.Thanks!
program247365
Seems like the export gets to a certain point with my site in dev, and then never continues, and never errors out. I let it run for about 3 hours and it didn't have another timestamp/entry in the log. It only ran for about 15 minutes and stopped logging/working. Ugh.
program247365