Monday, January 3, 2011

Exporting SharePoint web and Importing to same SiteCollection (part 2)

Read (Part 1) before

The problem when You need to change web Url while importing must be solved manualy.

Add Event handler to import procedure.

import.Started += new EventHandler<SPDeploymentEventArgs>(OnSiteImportStarted);
private void OnSiteImportStarted(object sender, SPDeploymentEventArgs args)
{
  SPImportObjectCollection rootObjects = args.RootObjects;
  if (rootObjects.Count != 0)
  {
   if (rootObjects.Count != 1)
   {
    for (int i = 0; i < rootObjects.Count; i++)
    {
     if (rootObjects[i].Type == SPDeploymentObjectType.Web)
     {
      rootObjects[i].TargetParentUrl = m_webParentUrl;
      rootObjects[i].TargetName = m_webName;
      return;
     }
    }
   }
   else
   {
    rootObjects[0].TargetParentUrl = m_webParentUrl;
    rootObjects[0].TargetName = m_webName;
   }
  }
 }

Thanks to:
http://blog.falchionconsulting.com/

No comments:

Post a Comment