Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Migration API only moves one item in library, not all

$
0
0

I have a console application that needs to move document library items, meta-data, versions from one library to another.

The following code works and I can verify in my export folder all the items are getting exported, but the import procedure below only imports one document library item...not all of them.

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

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

 static void ExportDocLibItem()
        {
            SPSite site = new SPSite(http://localhost);
            SPWeb web = site.OpenWeb("/");
            SPList list = web.Lists["Library1"];

            SPExportObject exportObject = new SPExportObject();
            exportObject.Id = list.ID;
            exportObject.Type = SPDeploymentObjectType.List;

            SPExportSettings exportSettings = new SPExportSettings();
            exportSettings.ExportObjects.Add(exportObject);
            exportSettings.FileLocation = @"c:\exportList5";
            exportSettings.FileCompression = false;
            exportSettings.SiteUrl = "http://localhost";

            SPExport export = new SPExport(exportSettings);
            export.Run();

            // cleanup
            web.Dispose();
            site.Dispose();
        }

        static void ImportDocLibItem()
        {
            SPImportSettings settings = new SPImportSettings();
            settings.SiteUrl = "http://localhost";
            settings.FileLocation = @"c:\exportList5";
            settings.FileCompression = false;
            settings.RetainObjectIdentity = false;

            SPImport import = new SPImport(settings);

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

            import.Run();
        }

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

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

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

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

I can watch via Debugger/Watch that there's only a single loop happening in OnImportStarted, so that's why only one library item I'm assuming.

Please advise.

Thank you!



Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>