Deep Dive into the SharePoint Content Deployment and Migration API – Part 3

[Part 1Part 2Part 3Part 4Part 5 – Part 6 – Part 7]

Providing some real world samples for import

After we managed to export content in part 2 lets now focus on the importing side. Import actually has two different ways to work:

  • Import by preserving the object identity and location
  • Import without preserving the object identity

The first method is used in the Content Deployment function available through the Central administration page. The second method is used by STSADM -o import and when doing the Copy/Move operations in Site Manager. The first method is similar to the import method used in CMS 2002: the imported objects will get the same GUIDs as on the source system. The second method on the other hand allows to import items at different places in the site collection hierarchy and can therefore be used for copy operations.

To demonstrate how powerful the Content Deployment and Migration API is in this area I will again provide some real world examples.

  1. Import by preserving the object identity
  2. Change the Parent of the imported objects during Import

The examples below assume that the destination site collection is on the local server on port 2001.


1) Import with preserving the object identity

A pre-requesit of this method is that the parents of all imported objects need to be in the destination database. So it is not possible to use this method to import into a site collection with a different structure. Usually it means you will use this in classic staging scenarios where you have an authoring farm, a staging farm and a production farm. The content is initially created on the authoring farm and then deployed to the staging farm.

For this method it doesn’t matter if the package only contains a single list item or a web or a complete site collection. It also doesn’t matter if the export has been done using incremental deployment or using full deployment. As all parents for the objects in the package need to be in the destination database the import engine will correctly import the items.

If you have different site collections and need to exchange data between these (e.g. copy a document library from the site collection of http://www.company1.com/ to the site collection of http://www.company2.com/ you need to use the method without preserving the object identity.

SPImportSettings settings = new SPImportSettings();
settings.SiteUrl = "http://localhost:2001";
settings.FileLocation = @"c:\export";
settings.FileCompression = false;
settings.RetainObjectIdentity = true;

SPImport import = new SPImport(settings);

import.Run();  

Similar to the export process we first create an object to configure the import. This is done by using the SPImportSettings method.

Here is a short explanation about the settings I used to perform the import:

  • SiteUrl – this is the Url to the destination site collection the import process will use.
  • FileLocation – this is the directory holding the data that needs to be imported
  • FileCompression – this defines whether the exported data is available in compressed or uncompressed format
  • RetainObjectIdentity – this defines whether to preserve the object identity during import or whether not to preserve the identiy. If the value is true the identity of the objects is preserved. Means Guid and Url of the imported items will be the same as on the exporting server. Be aware that this means that the parent objects of all imported need to be available in the destination database. If the value is false the objects will get a new generated Guid during import and it will be possible to control the parent of the imported root objects during import. We will cover this later.


2) Change the Parent of the imported objects during Import

Let’s assume we have exported a list from a source site collection using the steps described in point 3 of part 2. And now we would like to import the list into a different web in the destination site collection. It doesn’t matter if the destination site collection is the same site collection as the source or if it is in the same database as the source site collection. It also doesn’t matter if the destination site collection is in the same or a different farm as the source site collection.

If you export an item from a database (e.g. a list) without exporting it’s parent, then the exported item will become orphaned in the package. A package can contain multiple different orphaned objects (e.g. if you export multiple different lists or list items).

The import method allows us to define a new parent for each orphaned object in the export package. Means if you selected web A to be exported and web B where web B is a sub web of web A then you can only change the parent of web A. The parent of web B will always be web A as web B is not orphaned in the export package.

There are actually two methods that can be used to assign a new parent to orphaned objects:

Method 1 – all orphaned objects should be imported into the same sub web

This method will only work if all items need to be added to the same sub web. E.g. if you have exported a couple of lists and document libraries (even from different source webs) and now would like to import them into the same sub web.

SPImportSettings settings = new SPImportSettings();
settings.SiteUrl = "http://localhost:2001";
settings.WebUrl = "http://localhost:2001/MyDestWeb";
settings.FileLocation = @"c:\export";
settings.FileCompression = false;
settings.RetainObjectIdentity = false;

SPImport import = new SPImport(settings);
import.Run();

There are two important settings that are required to get this working:

  • WebUrl – this property defines the web that will be used as the new parent for all orphaned objects in the export package. This method (e.g.) cannot be used if the package contains orphaned documents as a web cannot be the parent of a document. The parent of a document needs to be a list or a folder.
  • RetainObjectIdentity – this defines whether to preserve the object identity during import or whether not to preserve the identity. If the value is false the objects will get a new generated Guid during import and it will be possible to assign a new parent to the imported orphaned objects.

Method 2 – assign an individual parent to each orphaned object

This method is more flexible than Method 1 but also requires a little bit more coding. Here it will be required to intercept the import process to assign a new parent to each orphaned object after the import process has gathered the list of orphaned objects from the import package.

This can be done using a custom event handler:

static void OnImportStarted(object sender, SPDeploymentEventArgs args)
{
   SPSite site = new SPSite(“http://localhost:2001”);
   SPWeb web = site.RootWeb;

   SPImportObjectCollection rootObjects = args.RootObjects;
   foreach (SPImportObject io in rootObjects)
   {
      io.TargetParentUrl = web.Url;
   } 

   web.dispose();
   site.dispose();
}  

The event handler above does such a “re-parenting” of all orphaned objects which are provided in the RootObjects collection of the event arguments. In the sample above we do actually the same as in the sample provided in Method 1: we assign a fixed web as the new parent of all objects. But you can easily extend the logic in this event handler to (e.g.) assign a different parent based on the object type:

static void OnImportStarted(object sender, SPDeploymentEventArgs args)
{
   SPSite site = new SPSite(“http://localhost:2001”);
   SPWeb web = site.RootWeb;
   SPList list = web.Lists[“MyDocLib”];

   SPImportObjectCollection rootObjects = args.RootObjects;
   foreach (SPImportObject io in rootObjects)
   { 
      if (io.Type == SPDeploymentObjectType.ListItem)               
      {                                                             
         io.TargetParentUrl = list.RootFolder.ServerRelativeUrl;    
      }                                                             
      if (io.Type == SPDeploymentObjectType.List)                   
      {                                                             
         io.TargetParentUrl = web.Url;                              
      }                                                             
      …                                                           

   }

 
   web.dispose();
   site.dispose();
}  

As you can see the eventhandler can be extended pretty easily. Beside looking on the Object type you could also look at the original TargetParentUrl to see where the source was located and include this in your “routing” logic. Now we need to see how we can hookup this event handler with the import process. This can be done as follows:

static void ImportDocLibItem()
{
   SPImportSettings settings = new SPImportSettings();
   settings.SiteUrl = “http://localhost:2001”;
   settings.FileLocation = @”c:\deployment5″;
   settings.FileCompression = false;
   settings.RetainObjectIdentity = false;

   SPImport import = new SPImport(settings);

   EventHandler<SPDeploymentEventArgs> eventHandler = new EventHandler<SPDeploymentEventArgs>(OnImportStarted);
   import.Started += eventHandler;

   import.Run();
}

As you can see you need to register the event handler with the import class before starting the import process.

There are a couple more event handlers that can be registered during import which are explained in more details on MSDN:
http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.deployment.spimport_events.aspx

Similar events can also be registered for export if required:
http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.deployment.spexport_events.aspx


3) Importing using compression

When importing using compression additional settings in the SPImportSettings object need to be adjusted:

SPImportSettings settings = new SPImportSettings();
settings.FileLocation = @”c:\export”;
settings.FileCompression = true;
settings.BaseFileName = “ExportedItems.cmp”;
… 

Here is an explanation about the two properties:

  • FileCompression – this property defines whether the content is available as a CAB file or in uncompressed format.
  • FileLocation – this property defines where the export files can be found. If compression is used it defines the location of the compressed content migration pack.
  • BaseFileName – this property is only used if compression is enabled. It defines the name of the compressed content migration pack file. The default extension (if not specified) is “.cmp”.

In Part 4 I will cover specific scenarios like adjusting links in move scenarios. E.g. if an image is moved to a new location you would need to adjust the links in all pages that reference this image.

131 Comments


  1. Stefan is back! J Stefan is in Redmond this week, and we had a chance to catch up! In fact, I had dinner

    Reply

  2. Stefan Goßner taucht in einer vierteiligen Serie in die Tiefen der SharePoint Deployment und Migration

    Reply

  3. Fantastic, incredibly detailed, content on content deployment by Stefan

    Reply

  4. [via Stefan Gossner ] This past week I was in Redmond teaching my WCM401 development class in an open

    Reply

  5. Body: Great series of posts by Stefan on how to use the Content Migration API. Very timely for me as

    Reply

  6. 今天凌晨加班的时候偶然翻到 Stefan Gossner 的这几篇文章,强烈推荐给大家: Deep Dive into the SharePoint Content Deployment and Migration

    Reply

  7. Hi.. this is an incredible article for demonstrating migration. However I may sound silly but could you advise me whether migration can be done on different environments like  production to pre-production and vise a versa.

    Reply

  8. Hi Purushotam,

    I’m not sure if I understand what you mean. Migration is usually moving content from a different system into sharepoint.

    Moving content between different SharePoint farms is referred to as deployment.

    The API I showed above can do both.

    If you need further info, please provide more details about what you are looking for.

    Cheers,

    Stefan

    Reply

  9. Great set of articles by Stefan Goßner : Deep Dive Into the SharePoint Content Deployment…

    Reply

  10. MOSS / SharePoint Content Deployment

    Reply

  11. hello , i want to import a item from a list source to another list of another site with web service … Can you help me ???

    Reply

  12. Hi Issou,

    you need to create a webservice based on the code parts I presented in Part 2 and Part 3 of this article series.

    Cheers,

    Stefan

    Reply

  13. So if you&#39;ve read the earlier posts about the tool ( Introducing the SharePoint Content Deployment

    Reply

  14. Hi,

    Thanks for the great posts. I’m able to successfully export and Import a Web. Everything carried over fine except for the listviewwebparts. It doesn’t retain the selected View and the toolbar type. Can you please tell me if this is the expected behavior or I’m missing something?

    Thanks in advance

    Reply

  15. Hi Raja,

    this is a known problem in MOSS which has been fixed in hotfix 941422.

    Be aware that you cannot install this fix on top of SP1.

    In case you have SP1 installed you would need to wait a couple of weeks till the Post-SP1-Rollup patch for WSS/MOSS is available which will also contain the fix for this issue.

    Cheers,

    Stefan

    Reply

  16. Thanks Stefan. I have an environment with out SP1..I’ll apply the hotfix and check my luck.

    Thanks again!

    Reply

  17. Stefan,

    Hotfix 941422 didn’t solve my issue.. but this one seems to address the problem:

    http://support.microsoft.com/kb/931636

    strangely, this hotfix is available on requesy only..I requested the hotfix, will test it once I get it.

    Reply

  18. Hi Raja,

    941422 includes 931636.

    Cheers,

    Stefan

    Reply

  19. Hi Stefan,

    I m trying to build a custom tool that would migrate the content from MCMS 2002 system to Moss 2007. Would it be possible for you to help me out with resources. I have already seen your article as well as Content Deployment API but i can’t understand as to how can i get the  content of MCMS in a desired format as required by content deploymetn API.

    Thanks in advance.

    Mayur Joshi.

    Reply

  20. Hi Mayur,

    why would you like to do this using a custom tool? MOSS already ships with a conversion tool that does exactly that and migrates the content from MCMS to MOSS using this API.

    Can you clarify this?

    Cheers,

    Stefan

    Reply

  21. Hi Stefan,

    The reason i want to go for this custom tool is to migrate particular posting / template rather than doing a complete migration. The reason for doing this is to have control over the migration process. Would it be possible for me to build the same.

    Regards,

    Mayur Joshi.

    Reply

  22. Hi Mayur,

    sure you can do this.

    You can use the MCMS API to read the content and then you can build the XML schema description (http://msdn2.microsoft.com/en-us/library/bb249989.aspx) to build the package based on the information retrieved from MCMS and import it using the SharePoint deployment and migration API.

    Reply

  23. Stefan Goßner posted a great series of posts about the Content Migration API (formerly known as PRIME

    Reply

  24. [ Part 1 – Part 2 – Part 3 – Part 4 – Part 5 – Part 6 ] Requirements for a successful content deployment

    Reply

  25. I get a lot of errors each time we run content deployment tool. Not once did it run the first time successfully. I am new to Sharepoint and read this article but I have no clue as to where I should use this code. Please help.

    Reply

  26. This code is something you can use as an alternative for the out of the box content deployment.

    If you have actual problems to deploy you should read part 5 and 6 of this article series. If it still does not work you should open a support case with Microsoft.

    Reply

  27. Hi Stefan,

    I’ve followed your posts and have completed a content deployment of a site collection onto a new application on the same server.

    However the following are missing:

    Publishing feature is not enabled on any of the sites

    Content query web parts – have the following error – "List does not exist" "The page you selected contains a list that does not exist.  It may have been deleted by another user."

    I can fix the publishing feature activation with a custom feature.  And I assume that the CQWP are configured to point at the old site.  Is there a way of changing this during the import?

    Thanks,

    Nick

    Reply

  28. Hi Nick,

    features need to be installed but not activated on the destination server before running the import. During import the features should be enabled automatically if preserve object identity is used.

    The problem with the CQWP sounds as if you did not use perserve object identity. The CQWP stores the GUID of the list. If the GUID changes on the destination server the GUID stored in the CQWP is no longer valid and has to be manually adjusted.

    Cheers,

    Stefan

    Reply

  29. Hi Stefan,

    Thanks for the uber quick reply.

    Can I use preserve object identity if the import is to a different application on the same farm?

    Thanks,

    Nick

    Reply

  30. Hi Nick,

    yes. But you need a different web application with a different content database.

    Cheers,

    Stefan

    Reply

  31. Hi Stefan,

    I am trying to import files from file system into MOSS 2007 obtained by an export from SPS 2001, but randomly some of the imported elements have wrong metadata information.

    In the Manifest.xml file all the informations are correct, but in the final imported item the creation date is sometimes set as export date (date of manifest.xml creation) sometime as import date, and sometimes correctly to document creation date.

    Even the document title is sometimes set wrong, being set to document name, instead of document title as is in Manifest.xml.

    This behavior seems appears to random, in fact the same files have different values repeating the import.

    Thanks,

    Thomas

    Reply

  32. Hi Thomas,

    sorry I don’t think I understand the scenario. You cannot do export/import cross version. You can only import items that have been exported from the same version.

    Cheers,

    Stefan

    Reply

  33. Hi Stefan,

    I also wanted to know if there’s a way to import check out data (checked out by, expiration etc..).

    If not by API than by manipulating the exported Manifest.xml.

    Thanks.

    Reply

  34. Hi Mor,

    the problem is not import.

    This data is usually not exported.

    Cheers,

    Stefan

    Reply

  35. hi stefan,

    i want to move items from one folder to another within same document library

    is it possible?

    Thank you

    Reply

  36. Hi Jack,

    that is even more simple. To move items in the same library you can use the item.MoveTo() method.

    Cheers,

    Stefan

    Reply

  37. Hi Stefan,

       When i am trying to Run SPImport.Run() to move a PagesLibrary i am getting error set "AllowUnsafeUpdates" to True.I tried setting that property on the Web but still i am facing the same problem.What could be the reason for this.I was able to do the same by using STSADM tool..

    Thanks In Advance,

    Rajee

    Reply

  38. Hi Rajeswari,

    are you executing this code as a Site Collection Administrator?

    Cheers,

    Stefan

    Reply

  39. hi stefan,

     I added my account to Site Collection Admin Group and tried running the same code.But still i am facing the same problem.Another thing is i added my code to the SPSecurity.RunWithElevatedPrivilages also.But i am still facing the same problem..

    Regards,

    Rajee

    Reply

  40. Hi Rajee,

    it looks as if you have implemented the import in a page which is called by a GET request. Try to use a POST request to call the page. Then this error should not occur.

    Cheers,

    Stefan

    Reply

  41. Hi stefan,

          What you said is exactly right.I was able to import.But is really wonderful bolg on Content Migration.

    cheers,

    Rajee

    Reply

  42. Hi stefan,

          I have another question regarding the Content Migration.If we need to archive the pages in the Pages Library to some other site Pages Library in different Server on timely basis.Is it possible to do with this.

    Regards,

    Rajee

    Reply

  43. Hi Rajee,

    yes you can do this.

    Cheers,

    Stefan

    Reply

  44. Hi Stefan,

          I need to Archive a Page in Pages Library to another Site.After Archiving i need to delete the page from that library along with that in need to delete the Page INSETS also.

    How i can achieve this.Literally speaking i need to Move a Page from One Site to another SiteCollection.How to do this…

    Cheers,

    Rajee

    Reply

  45. Hi Rajee,

    you need to do this in 3 steps:

    1) export from old site collection using the content deployment and migration API

    2) import into the new site collection using the content deployment and migration API

    3) delete the item in the source site collection using regular SharePoint object model.

    Cheers,

    Stefan

    Reply

  46. Hi Stefan,

      I did the same thing but problem here is my pages have content editors which have some documents from different libraries.If i am deleting the item from the Pages Library it is deleting the items from the pages library but i want to delete the rest of the contents which are embedded inside the Page.How can i achieve this in single shot like once i delete the page it should delete all the contents along with the documents embedded inside the Page from thier respective libraries.

    Regards,

    Rajee

    Reply

  47. Hi Rajee,

    you mean you would like to delete the items stored in other libraries?

    You would need write code to parse the content of each field and potentially webpart to find the linked items and then delete them.

    Cheers,

    Stefan

    Reply

  48. Hi Rajee,

    this settings actually increases the memory consumption as the callstack has to be gathered during allocation and kept during the whole lifecycle of the request. It also slightly slows down the processing.

    So this should only be used during troubleshooting.

    Cheers,

    Stefan

    Reply

  49. Stefan,

    We have a requirement to move a document from a custom library in one site collection to another site collection, while retaining metadata and version history.

    Can the export and import methods be used from a workflow? Any other pointers?

    Thanks!

    Reply

  50. hi stefan,

          I have one Context Menu attached to the Edit Control Block of the Pages Library.

    When i click this Context Menu i want to export the Item to the destination Site Pages Library.

    Inorder to send this internally Context Menu is executing an Aspx Page.Problem i am facing is not able to exceute the Import Code on an Aspx Page.While importing i am getting  error as "AllowUnsafeupdates" are not allowed on "Get" request.I tried setting the action property as "POST".How to execute the Import code in an Aspx Page.

    Regards,

    Rajee

    Reply

  51. Hi Parag,

    the export/import API should work inside a workflow. But be aware that you need be site collection administrator to perform the import operation.

    Cheers,

    Stefan

    Reply

  52. Hi Rajee,

    you have to ensure that the request to the ASPX page is performed as a postback and not as a GET request.

    Cheers,

    Stefan

    Reply

  53. hi stefan,

        I am facing one issue while exporting a Page to another site collection.

    Scenario goes like this…

    I have a Page which  have some documents as links on that page.These documents are coming from different folders of sitecollection documents.I was able to export properly that page for some times…After exporting it for couple times i am getting an exception as given below

    "Violation of PRIMARY KEY constraint ‘PK__#ExportObjects____XXXXXXXX’. Cannot insert duplicate key in object ‘dbo.#ExportObjects’"

    What could be the reason for this…

    if i do ExcludeDependencies as "true" then there are no issues but it is not copying the Embedded images etc..

    Why i am getting this kind of exception.

    Thanks,

    Rajee

    Reply

  54. Hi Rajee,

    please ensure to install the MOSS infrastructure update. It contains a couple of fixes for similar problems.

    Cheers,

    Stefan

    Reply

  55. Hi Stefan

    A company has requirements to publish pressreleases immediately (at least a short time) after the user clicks on the publish button.

    Authoring farm (domain A) export

    (import) on Production farm (domain B)

    The solution I’m working on is a feature event receiver that triggers on the ItemUpdated event.

    The ListItem gets exported (works fine) on the authoring farm. Since the production farm is on another domain, and the SPImport must execute local, the exported file is transferred to the target/productionfarm via a webservice.

    The webservice then executes the import.

    Everything works fine if the listitem exists on the target (Pages) list, as a regular update. But if the listitem is NEW the import fails.

    So the export/import is successful when it’s a regular update. But it fails when a new item is trying to get imported.

    /Kent

    EXPORT CODE: from the event receiver

    private bool ExportPressReleases(SPItemEventProperties properties)

           {

               string fileName = GetFileName(properties);

               try

               {

                   SPExportObject exportObject = new SPExportObject();

                   exportObject.Id = properties.ListItem.UniqueId;

                   exportObject.Type = SPDeploymentObjectType.ListItem;// ListItem;

                   exportObject.ParentId = properties.ListId;

                   exportObject.ExcludeChildren = true;

                   SPExportSettings exportSettings = new SPExportSettings();

                   exportSettings.ExportObjects.Add(exportObject);

                   if (_write2Log)

                   {

                       exportSettings.LogExportObjectsTable = true;

                       exportSettings.LogFilePath = ExportDirectory + "exportobject.log";

                   }

                   exportSettings.ExcludeDependencies = true;

                   exportSettings.FileLocation = ExportDirectory;

                   exportSettings.FileCompression = true;// true;

                   exportSettings.BaseFileName = fileName;

                   exportSettings.IncludeSecurity = SPIncludeSecurity.None;

                   exportSettings.SiteUrl = GetSiteUrl(properties);// properties.ListItem.Web.Site.Url;//"http://localhost:12002&quot;;

                   SPExport export = new SPExport(exportSettings);

                   export.Error += new EventHandler<SPDeploymentErrorEventArgs>(export_Error);

                   export.Completed += new EventHandler<SPDeploymentEventArgs>(export_Completed);

                   export.Started += new EventHandler<SPDeploymentEventArgs>(export_Started);

                   export.Run();

                   export.Dispose();

               }

               catch (Exception exe)

               {

                   return false;

               }

               return true;

           }

    IMPORT CODE from the webservice

    SPSecurity.RunWithElevatedPrivileges(delegate()

               {

                   LogMessage("Elevated user " + System.Security.Principal.WindowsIdentity.GetCurrent().Name);

                   SPImportSettings settings = new SPImportSettings();

                   settings.SiteUrl = “http://vpc-ols:12001”;

                   settings.WebUrl = “/pressreleases”;

                   settings.FileLocation = @fileLocation;

                   settings.BaseFileName = baseFileName;

                   if (LogMessages)

                       settings.LogFilePath = ImportDirectory + "importobjects.log";;

                   settings.IgnoreWebParts = true;

                   settings.FileCompression = true;

                   settings.RetainObjectIdentity = true;// retainObjectIdentity;

                   settings.SuppressAfterEvents = true;

                   SPImport import = new SPImport(settings);

                   import.Canceled += new EventHandler<SPDeploymentEventArgs>(import_Canceled);

                   import.Completed += new EventHandler<SPDeploymentEventArgs>(import_Completed);

                   import.Error += new EventHandler<SPDeploymentErrorEventArgs>(import_Error);

                   import.ObjectImported += new EventHandler<SPObjectImportedEventArgs>(import_ObjectImported);

                   import.Started += new EventHandler<SPDeploymentEventArgs>(import_Started);

                   import.Uncompressing += new EventHandler<SPDeploymentEventArgs>(import_Uncompressing);

                   import.ProgressUpdated += new EventHandler<SPDeploymentEventArgs>(import_ProgressUpdated);

                     import.Run();

                     import.Dispose();

               });

    EXPORT LOG

    [10/16/2008 3:37:36 PM]: Start Time: 10/16/2008 3:37:36 PM.

    [10/16/2008 3:37:36 PM]: Progress: Initializing Export.

    [10/16/2008 3:37:36 PM]: Progress: Starting Export.

    [10/16/2008 3:37:36 PM]: Progress: Calculating Objects to Export.

    [10/16/2008 3:37:37 PM]: Progress: Serializing Objects to Disk.

    [10/16/2008 3:37:37 PM]: Progress: Starting to process objects of type Site.

    [10/16/2008 3:37:37 PM]: Progress: Finished processing objects of type Site.

    [10/16/2008 3:37:37 PM]: Progress: Starting to process objects of type Folder.

    [10/16/2008 3:37:37 PM]: Progress: Exporting Folder /pressreleases/Pages/Forms/Press Release Page.

    [10/16/2008 3:37:37 PM]: Progress: Finished processing objects of type Folder.

    [10/16/2008 3:37:37 PM]: Progress: Starting to process objects of type ContentType.

    [10/16/2008 3:37:37 PM]: Progress: Finished processing objects of type ContentType.

    [10/16/2008 3:37:37 PM]: Progress: Starting to process objects of type DocLibFile.

    [10/16/2008 3:37:37 PM]: Progress: Exporting File pressreleases/Pages/yuk4.aspx.

    [10/16/2008 3:37:37 PM]: Progress: Finished processing objects of type DocLibFile.

    [10/16/2008 3:37:37 PM]: Progress: Starting to process objects of type ListItem.

    [10/16/2008 3:37:37 PM]: Progress: Exporting ListItem pressreleases/Pages?id=28.

    [10/16/2008 3:37:37 PM]: Progress: Finished processing objects of type ListItem.

    [10/16/2008 3:37:38 PM]: Progress: Creating File(s).

    [10/16/2008 3:37:38 PM]: Progress: Compressing File(s).

    [10/16/2008 3:37:38 PM]: Progress: Export Completed.

    [10/16/2008 3:37:38 PM]: Finish Time: 10/16/2008 3:37:38 PM.

    [10/16/2008 3:37:38 PM]: Completed with 0 warnings.

    [10/16/2008 3:37:38 PM]: Completed with 0 errors.

    IMPORT LOG

    [10/16/2008 3:37:38 PM]: Start Time: 10/16/2008 3:37:38 PM.

    [10/16/2008 3:37:38 PM]: Progress: Initializing Import.

    [10/16/2008 3:37:38 PM]: Progress: Starting content import.

    [10/16/2008 3:37:38 PM]: Progress: De-Serializing Objects to Database.

    [10/16/2008 3:37:38 PM]: Progress: Importing Folder /pressreleases/Pages/Forms/Press Release Page.

    [10/16/2008 3:37:43 PM]: Progress: Importing File Pages/yuk4.aspx.

    [10/16/2008 3:37:43 PM]: Progress: Importing ListItem /pressreleases/Pages?id=28.

    [10/16/2008 3:37:43 PM]: FatalError: Operation is not valid due to the current state of the object.

      at Microsoft.SharePoint.WebControls.SPControl.SPWebEnsureSPControl(HttpContext context)

      at Microsoft.SharePoint.WebControls.SPControl.GetContextWeb(HttpContext context)

      at Microsoft.SharePoint.SPContext.get_Current()

      at Microsoft.SharePoint.SPListItem.GetValue(SPField fld, Int32 columnNumber, Boolean bRaw)

      at Microsoft.SharePoint.SPListItem.GetValue(String strName, Boolean bThrowException)

      at Microsoft.SharePoint.SPListItem.GetValue(String strName)

      at Microsoft.SharePoint.SPListItem.get_Item(String fieldName)

      at Microsoft.SharePoint.SPListItem.SetValue(String strName, Object value, SPField field, Boolean protectFields)

      at Microsoft.SharePoint.SPListItem.SetValue(String strName, Object value, Boolean protectFields)

      at Microsoft.SharePoint.SPListItem.set_Item(String fieldName, Object value)

      at Microsoft.SharePoint.SPModerationInformation.set_Status(SPModerationStatusType value)

      at Microsoft.SharePoint.Deployment.ListItemSerializer.SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)

      at Microsoft.SharePoint.Deployment.XmlFormatter.ParseObject(Type objectType, Boolean isChildObject)

      at Microsoft.SharePoint.Deployment.XmlFormatter.DeserializeObject(Type objectType, Boolean isChildObject, DeploymentObject envelope)

      at Microsoft.SharePoint.Deployment.XmlFormatter.Deserialize(Stream serializationStream)

      at Microsoft.SharePoint.Deployment.ObjectSerializer.Deserialize(Stream serializationStream)

      at Microsoft.SharePoint.Deployment.ImportObjectManager.ProcessObject(XmlReader xmlReader)

      at Microsoft.SharePoint.Deployment.SPImport.DeserializeObjects()

      at Microsoft.SharePoint.Deployment.SPImport.Run()

    [10/16/2008 3:37:43 PM]: Progress: Import Completed.

    [10/16/2008 3:37:43 PM]: Finish Time: 10/16/2008 3:37:43 PM.

    [10/16/2008 3:37:43 PM]: Completed with 0 warnings.

    [10/16/2008 3:37:43 PM]: Completed with 1 errors.

    Reply

  56. Hi Kent,

    do you have the infrastructure update installed on the server?

    If yes, please open a support case with Microsoft to get this analyzed.

    Cheers,

    Stefan

    Reply

  57. Yes, all updates are installed, and I opened a case this afternoon 🙂

    Thanks for the great post…

    /Kent

    Reply

  58. FYI.

    We added

    SPUtility.ValidateFormDigest()

    just before

    SPSecurity.RunWithElevatedPrivileges

    And the import run smooth as silk 🙂

    The security flags wasnt correct for the context of the request since the import was handled by a webservice.

    /Kent

    Reply

  59. I’m fairly new to SharePoint but recently launched a Publishing website with content (some 4000 pages) imported from and external source.  Now I have been tasked to automate an import procedure for quarterly updates to aforementioned content without overwriting edits done after the initial import and preserving a content web part managed at the page level on each of the 4,000 pages.

    Is this API the best way (or even A way at all) to achieve this?

    Reply

  60. Hi Carin,

    this API can be used to import content – but it will not prevent overwrite of updated content. All imported content will overwrite existing content.

    So you would need to implement some logic in your code which ensures that no items which should not be imported are in the import package passed into the API.

    Cheers,

    Stefan

    Reply

  61. Hi Stefan,

    Really a nice article for content migration.

    I had a Question:

     Is there anyway to Migrate/Export/BackUp a Site (Not Site Colletion) as Site Colletion in different location.

    e.g. suppose i have a site http://<server>/Sites/Test/ABC. Now is there any method to move ABC site as http://<server&gt;:<PortNo>/Sites/ABC.

    Any pointers will be greatly appreciated.

    Thanks

    Saroj

    Reply

  62. Hi Saroj,

    unfortunatelly this is not supported in the current version as there are problems with the resulting site. Reason is that in the rootsite you need to have various specific lists and properties which do not exist in a subsite. After migrating a subsite to a root site these items will be missing.

    Cheers,

    Stefan

    Reply

  63. Thanks Stefan,

    Greatly appreciate your prompt reply.

    Yes your concerns are quite valid.

    But when I did export/import for Site to SC.

    These are the problems I came across,

    All the activated feature need to be installed at destination and corresponding DLL in the appropriate location.

    When I fixed these still the "Page not Found" error was thrown, except for the Layout pages.

    Once I changed the Master Page, the basic features of the Site Collection now seems to be working. i.e. There were no more "page not found" error.

    Didn’t tested rigorously,yet to come across major issues for a light weight Site with just one workflow and few lists.

    Cheers,

    Saroj

    Reply

  64. We are upgrading to from WSS3.0 to MOSS 2007 at GM and the when running an import command on a 4 meg file it is looking one by one through 6400 users and 1600 groups.  It appears to be spending 99% of its time finding users possibly in Active Directory from all around the world.  Is there a better way to do  an import.

    Reply

  65. Hi Kevin,

    did you follow our design guidelines to assign AD groups rather than individual users to SharePoint groups and then assign SharePoint groups to sites and lists?

    Or did you not follow this guidance and directly assigned individual users to SharePoint items?

    Cheers,

    Stefan

    Cheers,

    Stefan

    Reply

  66. In the last couple of weeks I have seen several cases where STSADM import operations failed with random

    Reply

  67. Stefan, is it possible to import a document library using a different target name than the original file name? I.e. in site A I have a document library called "foo" and I export it. Then I want to import it into site B, but using the name "bar".

    I need this, because site B already contains a document library called "foo", which is totally unrelated to the other "foo", but inconveniently has the exact same (relative) URL.

    I was thinking on changing the value of the SPImportObject’s TargetName property using the OnImportStarted event, like you described. But according to the MSDN docs this is only valid for objects of type "Web".

    Reply

  68. Hi Leon,

    it would be required to modify the manifest.xml file to achieve this.

    Cheers,

    Stefan

    Reply

  69. Dear Stefan,

     Does the import job must run at destination server? For example, i run the export job on server A, so must the import job run at destination server B? Please give adivse. Thank!

    Frankie

    Reply

  70. Hi Frankie,

    yes the import has to be executed on a server in target farm.

    Cheers,

    Stefan

    Reply

  71. In the past I have released several blogs about the various problems that can occur with Content Deployment.

    Reply

  72. Hi Stefan,

    This is very good post. However, I have faced one problem during import content. I have one column called Assigned To and it’s type is person or group. After import task i found that it doesnot imported assigned to column data.

    Also, I have checked in Manifest.xml file and for assigned to column it shows id only with 2;# and no person name.

    Please let me know.

    Thanks and Regards,

    Rishi

    Reply

  73. Hi Rishi,

    I assume you exported and imported all security information?

    If yes, please open a support case to get this analyzed.

    Cheers,

    Stefan

    Reply

  74. Hi Saefan

    I have used the following code snippet:

    SPExportSettings exportSettings = new SPExportSettings();

    exportSettings.SiteUrl = web.Url;

                       exportSettings.ExportMethod = SPExportMethodType.ExportAll;

                       exportSettings.FileLocation = @"filepath";

                       exportSettings.FileCompression = false;

                       exportSettings.ExcludeDependencies = false;

    Also, One more query along with this.

    When i try to export content from list name "MyList" on "SiteA" and while import If i try to import on "SiteB" then it won’t allow me to do that. So i need to update "SiteA" name with "SiteB" in Manifest.xml file.

    Is this correct approch?

    Thanks and Regards,

    Rishi

    Reply

  75. Hi Rishi,

    you are not exporting security settings. Please ensure that you add exportSettings.IncludeSecurity.

    Only if you export all then the users get exported. That is required to have the user information available on the target.

    For the second issue, please check reparenting in my article series.

    Cheers,

    Stefan

    Reply

  76. Hi Stefan,

    The comments/questions I am trying to post do not appear here.

    Any reason why?

    Vlad.

    Reply

  77. It seems like it’s because of the size. Is there another way to contact you?

    Vlad.

    Reply

  78. Hi Vlad,

    on the upper left edge you will find an "email" link where you can contact me by mail.

    Cheers,

    Stefan

    Reply

  79. Hi Saefan

    I have added

    exportSettings.IncludeSecurity = All property in my code but still not able to import users for Assigned to column.

    FYI, I have set same property for ImportSettings.

    Plesae help me . Sorry to keep pinging you about same problem

    Thanks and Regards,

    Rishi

    Reply

  80. Hi Rishi,

    nice that you export them. Do you also import them? Because the same setting exists for the import phase.

    And you should also set the SPImportUserInfoDateTime option to import all.

    To ensure that the user information is exported and imported correctly.

    Cheers,

    Stefan

    Reply

  81. Hi Stefan

    Thanks Sir. Now i am able to import all correct data.

    Excellent and appreciate your help.

    Thanks and Regards,

    Rishi

    Reply

  82. Dear Stefan,

     Currenly, i need to export a source site content and then import to destination server immediately. As you mentioned that import job should be run at destination server, so once the exoprt action completed, if the deploy job setup on exporting server, think we need to ftp the cmp file to destination server and then call web service which located on destination server to run import. is it ok or any my misunderstanding? Please give advise. Btw, could you give advise how to implement the deployment between separate server more efficient?

    Best Regards,

    Frankie

    Reply

  83. Hi Frankie,

    your understanding is correct. That is exactly how content deployment implements the import. What is does in addition is that it creates and starts a timer job which runs in OWSTIMER.EXE to perform the actual import operation on the target to ensure that application pool recycling does not affect the import operation.

    Cheers,

    Stefan

    Reply

  84. Dear Stefan,

     Thanks for your quick answers. I still have some questions need your help. First, if the deployment is a frequence task, we should store the change token so that it could run with incremental update, is it right? Second, how we could implement our import job by using the timer job? Third, does the ftp is the only way to transport cmp file to destination server? Please give advise. Many thanks!

    Best Regards,

    Frankie  

    Reply

  85. Hi Frankie,

    content deployment as in MOSS stores the change token on the source server in a list. You could use a similar approach.

    Regarding the timer job: please use the SDK on how to implement a custom timer job.

    Regarding upload: you can use different methods: FTP or HTTP upload. copy to fileshare, …

    Cheers,

    Stefan

    Reply

  86. Stefan,

    I am facing a unique problem.

    —————-

    Current Scenario

    —————-

    1) There are sites built out of OOB MOSS Site definitions.

    2) Custom Site templates were created and few sites were based out of them

    Today all such site templates have been deleted. Sites based out of it are still working as site templates are connected to the site definition & those site definitions (OOB) are still in place

    **To prevent errors, Two New Custom Site Definitions were created. All newly created sites are based out of either of these custom site definitions & have no problem.

    NOW CLIENT Wants to move existing sites built out of OOB site definition & the deleted custom site templates to be migrated to the 2 newly created custom site definition.

    Q1) is it possible to change a site’s association with its site definition through code so that it points to new site definition(Corrected one with extra features)

    Q2) same question for site template scenario?

    Please suggest

    Reply

  87. Hi Shishir,

    I’m not aware about a possibility to achieve this.

    Cheers,

    Stefan

    Reply

  88. Dear Stefan,

     We just test our conent deployment program, run a console application do execute export action, call a web service to execute import action. Unluckly, we met import exception with something like "The underlying connection was closed". My questions is 1. how to solve such exception and how about the root case? 2. It look like even if the import fail, but there are still some contents be imported, is there any approachs to rollback these kind of contents? 3. Is there any good approach to handle import error? could we just cancel it when throws errors. Please give advise. Many thanks!

    Frankie

    Reply

  89. Hi Frankie,

    which connection got closed above? The http connection when uploading the data? What is the exact error message?

    Regarding rollback: rollback is not possible. When import fails then the already imported data will exist on the target while the not yet imported data will not be available.

    Cheers,

    Stefan

    Reply

  90. Dear Stefan,

     The exact error message we met as below:

    1. Call Import Service Error: System.Net.WebException: The underlying connection wa

    s closed: An unexpected error occurred on a receive. —> System.IO.IOException:

    Unable to read data from the transport connection: An existing connection was f

    orcibly closed by the remote host. —> System.Net.Sockets.SocketException: An e

    xisting connection was forcibly closed by the remote host

      at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size,

    SocketFlags socketFlags)

      at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 s

    ize)

      — End of inner exception stack trace —

      at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 s

    ize)

      at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)

      at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetriev

    edStream, Boolean probeRead)

      — End of inner exception stack trace —

    2. Import failed:Microsoft.SharePoint.SPException: The directory is not a subdirec

    ory of the root directory. (Exception from HRESULT: 0x80070090) —> System.Run

    ime.InteropServices.COMException (0x80070090): The directory is not a subdirect

    ry of the root directory. (Exception from HRESULT: 0x80070090)

      at Microsoft.SharePoint.Library.SPRequestInternalClass.ThrowError(Int32 dwEr

    )

      at Microsoft.SharePoint.Library.SPRequest.ThrowError(Int32 dwErr)

      — End of inner exception stack trace —

      at Microsoft.SharePoint.Library.SPRequest.ThrowError(Int32 dwErr)

      at Microsoft.SharePoint.SPFieldCollection.AddFieldToWeb(String strXml, Boole

    n checkDisplayName)

      at Microsoft.SharePoint.SPFieldCollection.AddFieldAsXmlInternal(String schem

    Xml, Boolean addToDefaultView, SPAddFieldOptions op)

      at Microsoft.SharePoint.Deployment.FieldTemplateSerializer.CreateField(SPWeb

    web, SerializationInfoHelper infoHelper)

      at Microsoft.SharePoint.Deployment.FieldTemplateSerializer.SetObjectData(Obj

    ct obj, SerializationInfo info, StreamingContext context, ISurrogateSelector se

    ector)

      at Microsoft.SharePoint.Deployment.XmlFormatter.ParseObject(Type objectType,

    Boolean isChildObject)

      at Microsoft.SharePoint.Deployment.XmlFormatter.DeserializeObject(Type objec

    Type, Boolean isChildObject, DeploymentObject envelope)

      at Microsoft.SharePoint.Deployment.XmlFormatter.Deserialize(Stream serializa

    ionStream)

      at Microsoft.SharePoint.Deployment.ObjectSerializer.Deserialize(Stream seria

    izationStream)

      at Microsoft.SharePoint.Deployment.ImportObjectManager.ProcessObject(XmlRead

    r xmlReader)

      at Microsoft.SharePoint.Deployment.SPImport.DeserializeObjects()

      at Microsoft.SharePoint.Deployment.SPImport.Run()

      at kaoctdotcommoss.deployment.webservice.KAOCTMOSS_ImportService.RunImport(S

    ring _fileLocation, String _baseFileName) in C:Documents and Settingszhangde

    esktopKAOCT.COMMOSSkaoctdotcommoss.deployment.webserviceImport.asmx.cs:line

    37

    ***************************************************

    Could you help to give advise. Many thanks!

    Frankie

    Reply

  91. Dear Stefan,

     As you mentioned at previous reply, when import fails then the already imported data will exist on the target while the not yet imported data will not be available. So, my question is:

    1. Actually, the whole import job is not completed, so when we re-import the same cmp file, does it will overwrite those imported data? Please give advise. Many thanks!

    Frankie

    Reply

  92. Sounds to me as if 2 is a follow up problem from 1.

    1 seems to be inside the webservice when the web service talks to the source who sends the export.

    Looks like a problem with the IIS configuration.

    Here is an article that explains how to change the IIS settings:

    http://support.microsoft.com/default.aspx?id=826210

    Reply

  93. Dear Stefan,

    Thanks for your quickly answers. As you mentioned at previous reply, when import fails then the already imported data will exist on the target while the not yet imported data will not be available. So, when we re-import the same cmp file, does it will overwrite those imported data? Please give advise. Many thanks!

    Frankie

    Reply

  94. Dear Stefan,

     Currently, our content deployment for whole site is completed. But it still has error as below.

    [2/19/2009 10:35:30 AM]: Progress: Importing File WorkflowTasks/NewForm.aspx.

    [2/19/2009 10:35:30 AM]: FatalError: A duplicate name "ISM_x0020_Information" was found.

      at Microsoft.SharePoint.SPFieldCollection.AddFieldToWeb(String strXml, Boolean checkDisplayName)

      at Microsoft.SharePoint.SPFieldCollection.AddFieldAsXmlInternal(String schemaXml, Boolean addToDefaultView, SPAddFieldOptions op)

      at Microsoft.SharePoint.Deployment.FieldTemplateSerializer.CreateField(SPWeb web, SerializationInfoHelper infoHelper)

      at Microsoft.SharePoint.Deployment.FieldTemplateSerializer.SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)

      at Microsoft.SharePoint.Deployment.XmlFormatter.ParseObject(Type objectType, Boolean isChildObject)

      at Microsoft.SharePoint.Deployment.XmlFormatter.DeserializeObject(Type objectType, Boolean isChildObject, DeploymentObject envelope)

      at Microsoft.SharePoint.Deployment.XmlFormatter.Deserialize(Stream serializationStream)

      at Microsoft.SharePoint.Deployment.ObjectSerializer.Deserialize(Stream serializationStream)

      at Microsoft.SharePoint.Deployment.ImportObjectManager.ProcessObject(XmlReader xmlReader)

      at Microsoft.SharePoint.Deployment.SPImport.DeserializeObjects()

      at Microsoft.SharePoint.Deployment.SPImport.Run()

    [2/19/2009 10:35:30 AM]: Progress: Import Completed.

    [2/19/2009 10:35:30 AM]: Finish Time: 2/19/2009 10:35:30 AM.

    [2/19/2009 10:35:30 AM]: Completed with 7 warnings.

    [2/19/2009 10:35:30 AM]: Completed with 1 errors.

     Could you please advise, is there any setting we missed? Since we create an empty side with stsadm command and think there should not have duplicated content. Many thanks!

    Frankie

    Reply

  95. Hi Frankie,

    it will overwrite the data if you used RetainObjectIdentity = true.

    The latest error indicates that you have duplicate columns on the source system.

    E.g. you created the column on a subweb and later created a column with the same name in the rootweb.

    That cannot be handled by content deployment.

    To resolve this, please rename the column in the rootweb to ensure that no duplicates exist.

    Cheers,

    Stefan

    Reply

  96. Hi Stefan,

    When running SPImport.import from a web page deployed on the 12 hive (as a feature), I have the error : "The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again. —> The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again."

    Everybody recommand that the solution is to set SPSite.AllowUnsafeUpdate = True. But in content deployment scenarios we have no SPSite or SPWeb object, we have just the SPImport object !

    So what can be the solution in this case (The administrator refuse to deactivate the validation in the centrale administration) ? and can you explain un please what’s the meaning of this security page validation ?

    Reply

  97. Hi Elhadi,

    you need to ensure that the deployment code is initiated through a http POST request. Not a GET request.

    That will solve the issue.

    Cheers,

    Stefan

    Reply

  98. i’m also getting the "AllowUnsafeUpdates" error but i have to use a GET request because i dont know any other way to make this page do what i need it to do (long story). are you sure there’s no other way to get around this mostly fun piece of sharepoint?

    Reply

  99. why are there so many security restrictions. wtf. just break the user’s arms and legs and they wont be able to hurt you…

    Reply

  100. when i run OnImported, eventArgs.SourceUrl is …/Word Document. the file is not called "Word Document". there is no such file. any tips for how to not make it point to something that doesnt exist and then error out?

    sorry if i sound upset, but sharepoint has been kicking me in the nuts since christmas. i appreciate how much detail was put into this page. i just wish it was enough

    Reply

  101. Hi,

    sorry this is hard coded. If the code is executed inside a web application you need to use the POST request. What you could do is to do do a GET to one page that then does a POST to the page that executes the API.

    Alternatively you can use a console application.

    Cheers,

    Stefan

    Reply

  102. Regarding the security restrictions: if a GET request could init this then any hit of a search engine or random visitor to the site could start export or import by just following a link to this page. That is not something you would like, right?

    Cheers,

    Stefan

    Reply

  103. Regarding your OnImported problem: sorry I did not get this. Can you please rephrase?

    Reply

  104. hi

    i managed to get around those unsafeupdates and security validation errors for now

    about the OnUpdate thing – i’m trying to export and import a .docx file. OnImport runs 3 times. the first time the SourceUrl points to "…/Word Document", then "…/Word Document/template.docx", then finally to the actual file. i guess it’s exporting more than just a single docx file. i probably have to take a closer look at how to control what gets exported/imported

    Reply

  105. Great article.. Thanks for posting that. It helped so much with something I needed to do. I had to copy lists as part of a data migration for a couple thousand mysites.

    Reply

  106. Hi Stefan,

    Great article and very useful for fresh deployments. The issue I have is that lists and document libs are updated on our live environment, our other environments are used for proving web parts etc and building new sites. Is there any clean way of importing a site or page but only importing the functional objects and structure and not the data or is it best practice to release the updated web parts/controls.

    Cheers Chris

    Reply

  107. Hi Chris,

    the answer is no. Content Deployment was designed with the focus on environments where changes all happen on the source system and populate down the route to the production system.

    Changes on staging or production can cause content deployment to fail or content deployment can overwrite changes done on the target.

    Cheers,

    Stefan

    Reply

  108. Hi Stefan,

    Can we use the Content Deployment API in a scenario whereby we want to just export the items in the Reusable Content list of our development server to UAT server?

    BN

    Reply

  109. Hi BN,

    I haven’t tried but I cannot see a reason why this would not work.

    Give it a try!

    Cheers,

    Stefan

    Reply

  110. Is it possible to retain list item identity at the same time re-parenting? I know it does not make sense if you are moving list item in the same content database.  But I am copying data between two web applications each having their own content database.

    When RetainObjectIdentity is true, the RootObjects collection is empty.  Therefore, I can’t reparent object’s parent.

    I need to do this because I need to import multiple times. I use this API to ship update to other sites periodically.

    Reply

  111. Hi Larry,

    no this is not possible.

    Cheers,

    Stefan

    Reply

  112. Hello Stefan,

    I am very glad that I found this article that has helped me a lot in what I am trying to do. I am fairly new to Sharepoint and now I am developing a page that contains a button that will move one website from a site collection to another as a part of a business workflow.

    I want to move from http://therootsite/proposals/thewebsite to http://therootsite/projects/thewebsite. As you can see everything remains the same just the site collection is different. I was able to export and it worked fine, no problems. Now I am filled with doubts about how to do the import. I exported it with the exclude dependencies false and include descendants to Content.

    The silly question that is eating my brain is the following: Should I create first a blank website in the site collection projects and then import the website to that one or in the importSettings.SiteUrl property I just put the desired URL and it will be created automatically (I just want to point out that I am extremely new to this again).

    Any advice will be greatly appreciated.

    Thank you very much.

    Reply

  113. Hi Isai,

    please create the target site collection using STSADM -o createsite and do not specify a template.

    The import will do the rest.

    Cheers,

    Stefan

    Reply

  114. Hello Stefan,

    thank you for the quick response.

    I think that you are suggesting that I should use the command to create it and then import it. Because I am programming all this in the page with the button I mentioned before, is there a way to do the creation of the website you mentioned using the deployment API or any other API in Sharepoint and the programatically do the import as well?

    Thanks in advance for your comments and suggestions.

    Regards

    Isai

    Reply

  115. Hi Isai,

    yes the SharePoint object model allows to do it.

    Cheers,

    Stefan

    Reply

  116. Hello Stefan,

    thank you for your information. I was able to create the website and now I am doing the part of the import. Every time that I run my code I get the following SPException:

    "The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again."

    The code I have to import the site to the newly created site is:

           private void ImportSite(string newlyCreatedSiteURL)

           {

               SPSecurity.RunWithElevatedPrivileges(delegate()

                {

                    //Import from the Export File

                    SPImportSettings importSettings = new SPImportSettings();

                    importSettings.SiteUrl = "http://phl-sptdev1&quot;;

                    importSettings.WebUrl = "http://phl-sptdev1/Projects/Isai-Import-Test&quot;;

                    importSettings.FileLocation = @"c:export";

                    importSettings.FileCompression = false;

                    importSettings.RetainObjectIdentity = false;

                    SPImport import = new SPImport(importSettings);

                    import.Run();

                    });

    As usual I would appreciate any light why I am getting this exception or where to head for information about this.

    Thanks and have a good day

    Isai

    Reply

  117. Hi Isai,

    sounds as if you are doing this using a web application.

    If this is a web application you need to ensure that the import is done with a POST request and not a GET request.

    Also ensure that the user account used is a site collection administrator.

    Cheers,

    Stefan

    Reply

  118. Well, POST doesn't help if the POST request isn't made from the "import" web. If it's external POST request, it doesn't work. What I want is user authentication and do not want form digest validation. AllowUnsafeUpdates = true and FormDigestSettings.Enabled = false doesn't work either. FormDigestSettings.Enabled = false works if it's throught web application general settings.

    Reply

  119. In case of import/export if the site is using windows authentication and the domain name is different at the two locations (source , target) is there a different way of handling the export, regarding the import/export of the  people and group.

    Thanks.

    Reply

  120. Hi Sudeepto,

    in this case you should export and import with WssOnly. That will only export and import the role definitions without the actual users. You can the assign different users to the roles on source and target.

    Cheers,

    Stefan

    Reply

  121. Hi,

    In the last part you have mentioned, we have to adjust SPImportSettings but the code snippet has SPExportSettings…?

    3) Importing using compression

    When importing using compression additional settings in the SPImportSettings object need to be adjusted:

    SPExportSettings settings = new SPExportSettings();

    Reply

  122. Hi Jaishree,

    good catch! Thanks a lot.

    I corrected the code.

    Cheers,

    Stefan

    Reply

  123. hi,

    Can i know if we can export a web, and try to extract a list/library for import?

    thanks

    Reply

  124. Hi Vijay,

    actually that is not simple as it does not mean just to remove content from the manifest. You would also have to create a new entry for the list in the RootObjects.xml file.

    It is recommended to export just the list/library rather than the web.

    Cheers,

    Stefan

    Reply

  125. Can I ask you a question about permission?

    I have a list with some permissions is set on each item. How can I retain that permission.

    Reply

  126. Hi Tuyen,

    you need to export with SPIncludeSecurity.All

    and import with SPIncludeSecurity.All and SPUserInfoDateTime.ImportAll

    Cheers,

    Stefan

    Reply

  127. Hi Stefan,

    How can we rename the object imported, then import to the destination folder?

    For example, I'd like to copy doc.txt file to doc1.txt file.

    Thanks

    Reply

  128. Hi Stephanie,

    this cannot be done directly. You would have to first export the content, then update the manifest.xml and replace the name of the target item and then import using patched information.

    Cheers,

    Stefan

    Reply

  129. Hi Stefan,
    Did you turn it into a ready-made tool? We have to copy a list to a new location and the ID’s have to stay the same.
    Cheers,
    Raphael

    Reply

    1. Hi Raphael,
      no I did not – but what you are planning to do requires the site collection relative URLs to be identical in source and target.
      As soon as you try to copy to a different site collection relative URL is different you cannot preserve the IDs.
      Cheers,
      Stefan

      Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.