none
How do I copy the items in a sharepoint 2010 list to another list?

    Question

  • Hi,

    I need to find a script that copies all items in a sharepoint 2010 list including meta data. Saving the list as a template with content copies the items over fine but doesn't preserve, for example, the "Created By" data. Is there a powershell script or some other script that I can use for this?

    Thanks.

    Friday, October 14, 2011 9:59 AM

Answers

  • I'm afraid so :( I'm close to solving this using custom managed client object model code. Basically I've copied the original list and in code I'm using caml to filter the original list on content type and adding those items to the copied list using the ListItemCreationInformation class before deleting those items from the original list using the DeleteObject method. This seems the only way to preserve metadata within two lists residing within the same SPWeb.

    Thanks all the same.

    • Marked as answer by Wayne Fan Thursday, October 20, 2011 9:07 AM
    Saturday, October 15, 2011 6:01 PM

All replies

  • Hi,

    There is a Copy function in Powershell which can be used to copy items from one list to other.

    The following link will give you an idea.

    http://mysharepointofview.com/2009/09/copy-items-from-one-list-to-another-using-powershell/

    Hope this helps !

    Friday, October 14, 2011 10:26 AM
  • I had previously seen this page but I can't seem to be able to download his script, can you?

    Thanks.

    Friday, October 14, 2011 10:32 AM
  • Hi,

    You can use Content and structure(OOB SharePoint feature) to copy all list items from one list to another with same site collection.

    this will get you in Site Action -> Site Settings.

     

    Another method you can use Import/Excport utility of shrepoint to copy content from one sote to another.

    here is good artical for it:

    For Export : http://technet.microsoft.com/en-us/library/cc262759(office.12).aspx

    For Import : http://technet.microsoft.com/en-us/library/cc261866(office.12).aspx

     this utility retains your list structure and other metadata about item.


    Thanks.... ________________ Baba
    • Edited by Babasaheb Friday, October 14, 2011 10:36 AM
    Friday, October 14, 2011 10:35 AM
  • Unfortunately SharePoint Foundation server does not offer this :( I am also using the managed client object model as I do not have direct access to the sharepoint server, i.e. I do not have access to SPWeb or SPSite etc only List, ClientContext etc.

    Thanks.

    Friday, October 14, 2011 10:42 AM
  • It's a SP 2010 not 2007 solution that I am looking for.

    Thanks for your links anyway.

    Friday, October 14, 2011 10:44 AM
  • Hey,

    Do you have acess to the central administration?

    You can do it using Backup and restore facility


    "The Only Way To Get Smarter Is By Playing A Smarter Opponent"
    Friday, October 14, 2011 11:25 AM
  • Hi..

    Content and structure facility is available in MOSS also.. and also you need not to access Cenrtal Admin.

    http://www.mossgeek.com/2009/02/how-to-manage-site-content-and-structure/

    go through this link it will give you detailed steps for same..


    Thanks.... ________________ Baba
    Friday, October 14, 2011 11:37 AM
  • Baba,

    I'm NOT using MOSS 2007, I'm using SharePoint Foundation Server 2010.

    Thanks

    Friday, October 14, 2011 12:28 PM
  • No, I don't have access to Central Administration :(
    Friday, October 14, 2011 12:28 PM
  • Hi..

    You can write Sharepoint designer workflow with single activity CopyItemActivity, and this is also supported is SharePoint Foundation

    Here is an artical which might help you to do so.

    http://msdn.microsoft.com/en-us/library/ms446847.aspx


    Thanks.... ________________ Baba
    Friday, October 14, 2011 12:34 PM
  • This link will help you, there are even examples http://stackoverflow.com/questions/10313/can-i-copy-files-to-a-network-place-from-a-script-or-the-command-line
    Cordialement, Met vriendelijke groeten, Gokan Ozcifci - SharePoint Infrastructure Consultant
    Friday, October 14, 2011 12:54 PM
  • Gokhan,

    That wasn't helpful, sorry! I need to use the sharepoint management shell in order to pull data from my sharepoint lists.

    Thanks.

    Friday, October 14, 2011 1:16 PM
  • Unfortuately I don't have access to the sharepoint server, i.e. I don't have the credentials to connect to the sharepoint site through sharepoint designer.

    Thanks.

    Friday, October 14, 2011 1:19 PM
  • Hey,

    Then as per my knowledge i dnt think your scenario is possible .


    "The Only Way To Get Smarter Is By Playing A Smarter Opponent"
    • Proposed as answer by Rahul A Mehta Tuesday, November 08, 2011 10:17 AM
    Friday, October 14, 2011 1:24 PM
  • here the code

     

    Get-ChildItem allows you to list files and directories, including recursively with filename filters. Copy-Item allows you to copy a file.

    There is a lot of overlap in terms of selecting the files, often Copy-Item on its own is sufficient depending on the details of what you need (eg. do you want to retain the folder structure?)

    To copy all *.foo and *.bar from StartFolder to DestFolder:

    Copy-Item -path "StartFolder" -include "*.foo","*.bar" -Destination "DestFolder"
    

    If you need to preserve the folder structure things get harder because you need to build the destination folder name, something like:

    Get-ChildItem -path "StartFolder" -recurse -include "*.foo","*.bar" |
      Foreach-Object { Copy-Item -path $_ -destination { $_.FullName -replace "StartFolder","DestFolder"}}
    

    Cordialement, Met vriendelijke groeten, Gokan Ozcifci - SharePoint Infrastructure Consultant
    Friday, October 14, 2011 1:30 PM
  • here the code

     

    Get-ChildItem allows you to list files and directories, including recursively with filename filters. Copy-Item allows you to copy a file.

    There is a lot of overlap in terms of selecting the files, often Copy-Item on its own is sufficient depending on the details of what you need (eg. do you want to retain the folder structure?)

    To copy all *.foo and *.bar from StartFolder to DestFolder:

    Copy-Item -path "StartFolder" -include "*.foo","*.bar" -Destination "DestFolder"
    

    If you need to preserve the folder structure things get harder because you need to build the destination folder name, something like:

    Get-ChildItem -path "StartFolder" -recurse -include "*.foo","*.bar" |
      Foreach-Object { Copy-Item -path $_ -destination { $_.FullName -replace "StartFolder","DestFolder"}}
    

    Cordialement, Met vriendelijke groeten, Gokan Ozcifci - SharePoint Infrastructure Consultant

    and the link is here: http://serverfault.com/questions/194827/writing-a-powershell-script-to-copy-files-with-certain-extension-from-one-folder
    Cordialement, Met vriendelijke groeten, Gokan Ozcifci - SharePoint Infrastructure Consultant
    Friday, October 14, 2011 1:31 PM
  • Hey,

    Please go thru this steps :

    1] Open List -> From the ribbon (choose Export to spreadsheet) ->Save the file .

    2] Next Go to site actions -> more options -> custom list section (Import Spreadsheet) and choose the file which was exported in above step.

    3]All the contents will be copied to the new list

    Hope this helps :)


    "The Only Way To Get Smarter Is By Playing A Smarter Opponent"
    Friday, October 14, 2011 1:39 PM
  • Ravi,

    I have already tried what you suggested, unfortunately this method does not persist the Created, Created By etc field data :(

    Thanks.

    Friday, October 14, 2011 1:51 PM
  • Gokhan,

    I'm not trying to copy a file structure of any sort, I'm trying to copy items within a sharepoint 2010 list into another list where fields such as Created By are persisted from the original list. I need to use powershell commands such as SPListItem etc but I'm not sure of the structure to use.

    Thanks.

    Friday, October 14, 2011 1:56 PM
  • Hi,

     

    Finaly, i have the code of POWERSHELL, for copying list's, here the code and link http://blogs.msdn.com/b/jorman/archive/2011/01/08/copying-lists-with-powershell-in-sharepoint-2010.aspx

     

       1: #This is the source web that is hosting the lists to move
       2: $sourceWebUrl = "http://server.SharePoint.Com/Sub1"
       3:  
       4: #This is the destination web, where the lists will be copied to
       5: $destWebUrl = "http://server.SharePoint.com/Sub1/forums"
       6:  
       7: #Location to store the export file
       8: $path = "\\Server\Share\"
       9:  
      10: #comma delimited list of List Names to copy
      11: $lists = @("List Number 1", "List Number 2")
      12:  
      13:  
      14: #Loop through the lists, export the list from the source, and import the list into the destination
      15: foreach($list in $lists)
      16: {
      17:     "Exporting " + $sourceWebUrl + "/lists/" + $list
      18:  
      19:         export-spweb $sourceWebUrl -ItemUrl ("lists/" + $list) -IncludeUserSecurity -IncludeVersions All -path ($path + $list + ".cmp") -nologfile
      20:  
      21:     "Exporting complete."
      22:  
      23:  
      24:  
      25:     "Importing " + $destWebUrl + "/lists/" + $list
      26:  
      27:         import-spweb $destWebUrl -IncludeUserSecurity -path ($path + $list + ".cmp") -nologfile
      28:  
      29:     "Importing Complete"
      30:     "`r`n`r`n"
      31: }

    Cordialement, Met vriendelijke groeten, Gokan Ozcifci - SharePoint Infrastructure Consultant
    Friday, October 14, 2011 4:10 PM
  • Are you trying to move the items to a seperate site collection?  It is my understanding that the PIDs are different across site collections because of the new User Information List that is created in the new collection.  Therefore, by default, it will not be possible to retain the Created/Created By, Modified/Modified information, without writing a custom code solution.


    Patrick Curran | Twitter | Blog
    Click "Mark as Answer" on the post that helps you.
    Click "Unmark as Answer" if a marked post does not actually answer your question.
    Click "Vote As Helpful" if a post has been useful to you.
    Friday, October 14, 2011 4:53 PM
  • Gokhan,

    When adapting the code to accommodate my setup (below) I seem to receive the error:"FullyQualifiedErrorId : Microsoft.SharePoint.Powershell.SPCmdletExportWeb"? and the TestCalendar.cmp file is not being created under C:\temp\?

    Thanks

    #This is the source web that is hosting the lists to move
    $sourceWebUrl = "http://portal"
    #This is the destination web, where the lists will be copied to
    $destWebUrl = "http://portal/mirror"
    #Location to store the export file
    $path = "C:\temp\"
    #comma delimited list of List Names to copy
    $lists = @("TestCalendar")
    #Loop through the lists, export the list from the source, and import the list into the destination
    foreach($list in $lists)
    {
    "Exporting " + $sourceWebUrl + "/Lists/" + $list
    export-spweb $sourceWebUrl -ItemUrl ("Lists/" + $list) -IncludeUserSecurity -IncludeVersions All -path ($path + $list + ".cmp") -nologfile
    "Exporting complete."
    "Importing " + $destWebUrl + "/Lists/" + $list
    import-spweb $destWebUrl -IncludeUserSecurity -path ($path + $list + ".cmp") -nologfile
    "Importing Complete"
    "`r`n`r`n"
    }


    Saturday, October 15, 2011 1:13 PM
  • No, I'm merely trying to move the items to a seperate list within the same site collection.

    Thanks.
    Saturday, October 15, 2011 1:24 PM
  • check out this custom feature and control that will help you to implement that

    http://splistkit.codeplex.com/wikipage?title=SP%20List%20Item%20Copy&referringTitle=Home

     


    Regards, Rami M. Nassar (MCP, MCTS, MCPD) My Blog: http://blog.raminassar.com E-Mail: rami.nassar@hotmail.com Don't forget to click Mark as Answer on the post that helped you.
    Saturday, October 15, 2011 1:24 PM
  • Rami,

    But can you copy the item to another list? From what I can see the tool only creates a copy of an item into the list that the item exists in. I need to copy items from one list to another list.

    Thanks.

    Saturday, October 15, 2011 5:14 PM
  • You can find the solution for your Problem here..

    http://social.technet.microsoft.com/Forums/en-PH/sharepoint2010setup/thread/a1f48e70-9360-440f-b160-525fbf2b8412

     

    My guess, is http://portal is not valid..

     


    Cordialement, Met vriendelijke groeten, Gokan Ozcifci - SharePoint Infrastructure Consultant ( wants to be microsoft community contributor )
    Saturday, October 15, 2011 5:16 PM
  • Copying items from list to another with reserving the Created, Created By, Modified, and Modified By; you can do this from Site Content and Structure, you can find it in the Site Settings from Site Actions menu.

    From there, you can go to your list, select the items you want to move and choose the Actions > Move, then choose where to move those items but there should list already created before moving the items. This will reserve the Created, Created By, Modified, and Modified By.


    Mai Omar Desouki | Software Consultant | Infusion | MCP, MCTS, MCPD, MCITP, MCT Microsoft Certified Trainer & MCC Microsoft Community Contributor | Email: mai_omar_86@live.com | Blog: http://moresharepoint.wordpress.com
    Saturday, October 15, 2011 5:40 PM
  • Gokhan,

    After further testing and digging around I have found that I cannot copy items within a list to another list within the same SPWeb using powershell's export and import. I can export and import the items to another list within, for example, a sub-site but not another list living at the same level as the list I am copying from. The .cmp file restricts the list to a specified name, therefore I cannot keep the existing list and copy it's items into another list at the same level.

    Thanks.

    Saturday, October 15, 2011 5:53 PM
  • Mai,

    Not within sharepoint foundation.

    Saturday, October 15, 2011 5:54 PM
  • oh my god, I made all this work than for nothing :(
    Cordialement, Met vriendelijke groeten, Gokan Ozcifci - SharePoint Infrastructure Consultant ( wants to be microsoft community contributor )
    Saturday, October 15, 2011 5:55 PM
  • I'm afraid so :( I'm close to solving this using custom managed client object model code. Basically I've copied the original list and in code I'm using caml to filter the original list on content type and adding those items to the copied list using the ListItemCreationInformation class before deleting those items from the original list using the DeleteObject method. This seems the only way to preserve metadata within two lists residing within the same SPWeb.

    Thanks all the same.

    • Marked as answer by Wayne Fan Thursday, October 20, 2011 9:07 AM
    Saturday, October 15, 2011 6:01 PM