6

I know you can backup site collections with stsadm -o backup, and you can backup sites with stsadm -o export. But what's the best way to copy a list? I've tried to use the save as a list template and include content, but not all the columns came across.

For example I had a lookup to another column in the same list but the data was totally messed up. only about 10% of the values were correct. I heard this is supposed to be available in 2010, but what's the best way to copy a list in 2007.

5 Answers 5

6

I used the stsadm extensions to be able to import and export lists and libraries.

2
  • Can you give me more info? I'm in the Air Force at work and the link you posted is blocked, as a lot of blogs and sites categorized as none are.
    – rgwaldron
    Commented Dec 4, 2009 at 16:26
  • It's a set of extensions for stsadm which allows you to export and import lists and libraries using the migration apis. Commented Dec 4, 2009 at 19:54
2

You have already tried the best way, Save as Template and add it to the New Site. And to make the Look Up field work refer to this article that provides an alternate to do it.

Also one another way if wanted to do is to Create a List Template and Deploy it as a Feature using WSP solution, but if you are going to use this List only Once then you don't need to create a List Template. One Another item to note in the List Template is you will have to Hand code the XML with the Data contained in the list. Here is a nice article on how to create a List Template.

1
  • I'll give that a shot. Will this also work with large lists or libraries ? I've heard that's another limitation.
    – rgwaldron
    Commented Dec 4, 2009 at 5:08
1

goign to Site Settings -> Site Content and Structure, I created a new list in the new site with it's default list structure. Then I went to the old list and selected all the data rows then copied them to the new list. SharePoint copied the data and the list structure to the new list and made the new list look and work just like the old list. I was very happy.

0

Using the content deployment wizard (http://spdeploymentwizard.codeplex.com/ ), you can export a specific List or document library and then import it to another site.

This is a graphical wizard that displays all site content in a tree like view then you can select what lists or libraries to export. You can then use it again to import whatever you exported to the new site.

0

I am not sure what is the best way, but I did it using a Console App, with following code,

        SPList myDestinationList = web1.Lists[destinationlistName];
        SPList mySourceList = web2.Lists[Form1.OldListName];
        SPQuery mySourceListQuery = new SPQuery();

        mySourceListQuery.Query =

            "<OrderBy><FieldRef Name='a' />" +
                     "<FieldRef Name='b' />" +
            "</OrderBy>";

        SPListItemCollection mySourceItemColl = mySourceList.GetItems(mySourceListQuery);
        foreach (SPListItem mySourceListItem in mySourceItemColl)
        {
            SPListItem myDestinationListItem = myDestinationList.Items.Add();

            if (mySourceListItem["a"] != null)
                myDestinationListItem["a"] = mySourceListItem["Title"];

            if (mySourceListItem["b"] != null)
                myDestinationListItem["b"] = mySourceListItem["Location"];


            web1.AllowUnsafeUpdates = true;
            web2.AllowUnsafeUpdates = true;
            myDestinationListItem.Update();
            web1.AllowUnsafeUpdates = false;
            web1.AllowUnsafeUpdates = false;
        }

It did worked with Custom columns and lookup columns as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.