SharePoint 2007 Object Model: How can I make a new site collection, move the original main site to b
Posted
by program247365
on Stack Overflow
See other posts from Stack Overflow
or by program247365
Published on 2010-05-04T13:37:08Z
Indexed on
2010/05/04
13:38 UTC
Read the original article
Hit count: 212
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
- Create a new site collection, with a main default site, on same SP instance (this is done, easy to do in SP Object Model)
- 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);
}
© Stack Overflow or respective owner