Copying list items from one list to another

Sep 8, 2009 at 10:49 AM

Hello,

I'm trying to use Beta 2.6 of the wizard to transfer list items from one list to another at a different URL. I have been able to export without any problems, however I'm not sure what options to choose so that I can perform the input. Perhaps this is not possible.

Are there options that can make this work?

Thanks,

Alex.

Coordinator
Sep 11, 2009 at 9:36 AM

Hi Alex,

Yes, this is certainly possible. On the import, you need to:

  • Set the 'Import web URL' to be the parent web where you want to the new list
  • *Don't* check 'Retain object IDs and locations'

That should then import the list to the new location fine. Let me know if you're still having issues..

Thanks,

Chris.

Sep 11, 2009 at 10:07 AM

The problem seems to be in specifying the destination list. For example:

The import is three items from /forums/Lists/Discussion/ThreadA. The export location is /alternate/Lists/Discussion. I'd like those items in ThreadA from the Discussion list in the forums site to be imported into the Discussion list in the alternate site.

Any ideas?

Thanks for getting back to me,

Alex.

Coordinator
Sep 11, 2009 at 11:01 AM

Hmm I see - so you're trying to import list items with a discussion list to another discussion.

I'm not sure if this will work without custom code unfortunately - BUT, the following is worth trying:

  • Set the 'Import Web Url' to the URL of the list - the Content Deployment API might then use this to find the list in this case

If not, I think the Wizard doesn't support this operation I'm afraid. You'd need code like this from Stefan's blog (which the Wizard doesn't currently have):

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();
HTH,
Chris.
Sep 11, 2009 at 11:27 AM

Unfortunately it doesn't work. I get this error:

---------------------------
Import error
---------------------------
An error occurred whilst running the import. The import log file will now be opened. 

Exception details: 

System.ArgumentException: Value does not fall within the expected range.
   at Microsoft.SharePoint.SPWeb.GetWebRelativeUrlFromUrl(String strUrl, Boolean includeQueryString, Boolean canonicalizeUrl)
   at Microsoft.SharePoint.SPWeb.GetWebRelativeUrlFromUrl(String strUrl)
   at Microsoft.SharePoint.SPWeb.GetFolder(String strUrl)
   at Microsoft.SharePoint.Deployment.ContentTypeSerializer.GetListByUrl(String parentUrl)
   at Microsoft.SharePoint.Deployment.ContentTypeSerializer.GetTargetList(Guid listId, Guid parentWebId, String scope, String contentTypeName)
   at Microsoft.SharePoint.Deployment.ContentTypeSerializer.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()
   at COB.SharePoint.Utilities.DeploymentWizard.Core.WizardDeployment.RunImport()
---------------------------
OK   
---------------------------

Would you be happy for me to try and add this functionality and submit as a patch?

 

Coordinator
Sep 11, 2009 at 3:11 PM

Alex,

I think so yep - I've avoided this scenario as I think there might be more to it underneath, but at the very least I'd be happy to have it as a 'special version' if your implementation doesn't cover everything. I'm not doubting your coding skills - if I rememember rightly, it's more about the breadth of variations of this scenario, and I'm not sure you'd want to tackle them all to solve your particular variant! I certainly appreciate your willingness to get involved.

Ping me on twitter if any questions as you go, I'll try to help.

Thanks,

Chris. 

Sep 17, 2009 at 4:18 PM

Hi Chris,

Good news, with your reference to Stefan's blog post I was able to add this functionality. See the patch list. These are the tested working scenarios:

  • discussion list threads including original author/editor information with UserInfoDateTime setting
  • documents in a document library, provided they are checked in
  • version history of documents in a document library
  • one level of sub-folders within a document library
  • Works with any URL to a list pasted in the "Import URL" box - tested this thoroughly and chose SPWeb.GetList() which seems very robust

Look for "AA: Check if importing to list" for the main addition to your code. I had to pass SPImportSettings through to get access to the WebUrl property. This meant changing the signature of the updateProgressOnDeployment delegate. As this is used by methods with different purposes I added a parameter of type object to do it. It's kind of ugly but the least intrusive change I could think of and may be useful if other methods need extra stuff passed through. You may wish to refactor.

Of course, more testing is needed against different list types and scenarios but this is good for me right now.

Regards and thanks for your help!

Alex.

Nov 30, 2009 at 2:08 PM

Hi,

first of all thanks for sharing your tool/code! i've installed the 2.7 beta and wanted to move documents from Doc-Lib A to Doc-Lib B within the same Web. But couldn't it to work.

Lets say Doclib A exists at http://<mySharepoint>/Test/DocumentsA and i want to move these files to http://<mySharePoint>/Test/DocumentsB (which also already exists).

What should i enter at Site URL and Import Web URL, to get it to work properly ?

Cheers,

Tim

 

 

 

Dec 23, 2009 at 11:21 AM

Hi Tim,

For site URL you should enter the URL of the site collection as usual. For web url, you should enter http://<mysharepoint>/test/documentsb. In fact I think you can use the same for both and the app will pull out what it needs. Of course, you need to export the original files from http://mysharepoint/test/documentsa first.

If this isn't working for you, what problems are you experiencing? Does nothing happen or do you receive an exception?

Apologies it's taken me so long to get back to you.

Best regards,

Alex

Jan 13, 2010 at 9:39 PM

Hi,

I exported a folder under my document library and am trying to import it to a doc library in a different farm and i have a couple of questions

Source : http://server1/docliba/folder

Destination: http://server2/doclibb/folder

1) What should the site and import web URL be ?

Does this look right?

Site url : http://server2

Import web url : http://server2/doclibb/folder

2) Should my folder on doclibb exist or would the import create it ?

Jan 13, 2010 at 9:49 PM

Hi papushka,

I'll answer for Chris as I added this feature - hopefully he doesn't mind!

When adding the feature I never tested how it might work between folders, it's only been designed for and tested against entire document libraries. Some things we can't do because the import/export engine provided by SharePoint that we use can't do everything, so I'm not sure if this is possible. Are you receiving a particular error or is it not behaving as expected?

Best regards,

Alex.