SharePoint Automation Gary Lapointe – Founding Partner, Aptillon, Inc.

18May/0811

Exporting and Importing List Folders

Those familiar with my commands know that I've got a few commands that I created to handle the exporting and importing of list items and lists using the content deployment API.  If you're familiar with the API then you know that there's also an option to export and import list folders.  Until a few weeks ago I didn't have a need for this so I hadn't bothered leveraging it but then I got a project which required migrating content from one farm to another, one folder at a time.  Fortunately I already had my other commands as a starting place so it only took me about an hour to build out two new commands: gl-exportlistfolder and gl-importlistfolder.  Note that I built and published the commands several weeks ago - I'm just way behind in getting them (and others) documented.

The commands are more or less identical to the gl-exportlist and gl-importlist commands which I used as a starting place.  The syntax and examples of the two commands are shown below starting with the export command:

C:\>stsadm -help gl-exportlistfolder

stsadm -o gl-exportlistfolder

Exports a list.

Parameters:
        -url <folder url>
        -filename <export file name>
        [-overwrite]
        [-includeusersecurity]
        [-haltonwarning]
        [-haltonfatalerror]
        [-nologfile]
        [-versions <1-4>
                1 - Last major version for files and list items
                2 - The current version, either the last major or the last minor
                3 - Last major and last minor version for files and list items
                4 - All versions for files and list items (default)]
        [-cabsize <integer from 1-1024 megabytes> (default: 25)]
        [-nofilecompression]
        [-includedescendants <All | Content | None>]
        [-quiet]

To export the root folder and no sub-folders (effectively giving you all items in the root folder without any sub-folders) you would run the following:

stsadm -o gl-exportlistfolder -url http://portal/documents -filename c:\exportdata\docs -nofilecompression -includedescendants none

To export a sub-folder and all of its child sub-folders you would run something similar to the following:

stsadm -o gl-exportlistfolder -url http://portal/documents/subfolder1 -filename c:\exportdata\docs -nofilecompression

And of course an export wouldn't be much good without an import:

C:\>stsadm -help gl-importlistfolder

stsadm -o gl-importlistfolder

Imports a list item or items.

Parameters:
        -url <url of list folder to import to>
        -filename <import file name>
        [-includeusersecurity]
        [-haltonwarning]
        [-haltonfatalerror]
        [-nologfile]
        [-updateversions <1-3>
                1 - Add new versions to the current file (default)
                2 - Overwrite the file and all its versions (delete then insert)
                3 - Ignore the file if it exists on the destination]
        [-nofilecompression]
        [-quiet]
        [-retargetlinks (resets links pointing to the source to now point to the target)]
        [-sourceurl <url to original source folder> (use if retargetlinks)]
        [-retainobjectidentity]

To import the documents that have been exported above you would run something like the following (note that the folder URL could be the URL of a sub-folder):

stsadm -o gl-importlistfolder -url http://portal/documents -filename c:\exportdata\docs -nofilecompression

Comments (11) Trackbacks (0)
  1. When I try this the import does indeed replicate the folder structure exported, but creates a top level folder above it. In your example this folder would be called Documents. Any Ideas?

  2. Hi,

    Great toolset!

    But i have do have a problem using it though.
    The commands are all working – but when i try to import my previously exported Lists folder – i get following error message:

    Progress: Importing File Lists/Workflow History/AllItems.aspx.
    Progress: Importing File Lists/Workflow History/DispForm.aspx.
    Progress: Importing File Lists/Workflow History/EditForm.aspx.
    Progress: Importing File Lists/Workflow History/NewForm.aspx.
    FatalError: Object reference not set to an instance of an object.
    at Microsoft.SharePoint.Deployment.ContentTypeSerializer.GetContentType(SPCon
    tentType sourceContentType, ImportObjectManager importObjectManager, Boolean isP
    arentSystemObject)
    at Microsoft.SharePoint.Deployment.ContentTypeSerializer.ProcessContentType(S
    PContentType sourceContentType, String contentTypeXml, ImportObjectManager impor
    tObjectManager, Boolean IsParentSystemObject)
    at Microsoft.SharePoint.Deployment.ContentTypeSerializer.SetObjectData(Object
    obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selec
    tor)

    I know SP 2007 is a bitobsolete but i still hope you can maybe enlighten me with this issue.

    Some more infos:
    I try to copy all SP Lists from one site to another – i have copied all the contenttypes, and all the workflows to the new site.But still the same error.

    Some hint what i might be missing?

  3. I keep getting an object reference error on the import.

    Start Time: 4/27/2011 2:25:20 PM.
    Progress: Initializing Import.
    Progress: Starting content import.
    Progress: De-Serializing Objects to Database.
    Progress: Importing Folder /Projects/site1/site2/Project Deliverables/Forms/Folder(-927379924).
    FatalError: Object reference not set to an instance of an object.
    at Microsoft.SharePoint.Deployment.ContentTypeSerializer.GetContentType(SPContentType sourceContentType, ImportObjectManager importO
    bjectManager, Boolean isParentSystemObject)
    at Microsoft.SharePoint.Deployment.ContentTypeSerializer.ProcessContentType(SPContentType sourceContentType, String contentTypeXml,
    ImportObjectManager importObjectManager, Boolean IsParentSystemObject)
    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()
    Progress: Import Completed.
    Finish Time: 4/27/2011 2:25:21 PM.
    Completed with 0 warnings.
    Completed with 1 errors.

  4. Just incase anyone else runs into the issue. I found that adding -retainobjectidentity to the import command resolved the issue.

  5. After I import the folder. From the output everything appears to be okay but the document library that I imported the folder into is empty. I got 0 errors and warnings though. Any clue why this would happen or what the cause would be? Does it have anything to do with retaining object identity when the new folder location is in a subsite within the same sitecollection? I greatly appreciate any help.

  6. Thanks for the feedback Gary. I was doing it without retaining object identity to start with but I was getting the object reference errors. Any help would be greatly appreciated. I have a looming deadline and this could be the solution to a major requirement. There are about 5000 docs in this one library we want to split up into subsites. Here is the command and output when I don’t retaing the object ID.

    stsadm -o gl-importlistfolder -url “http://siteCol/Projects/site1/site2/subsite/Documents/test” -file
    name “c:\exportdata\subsite1″ -nofilecompression

    Start Time: 4/30/2011 10:42:42 PM.
    Progress: Initializing Import.
    Progress: Starting content import.
    Progress: De-Serializing Objects to Database.
    Progress: Importing Folder /Projects/site1/site2/Project Deliverables/Forms/Folder(-927379924).
    FatalError: Object reference not set to an instance of an object.
    at Microsoft.SharePoint.Deployment.ContentTypeSerializer.GetContentType(SPContentType sourceContentType, ImportObjectManager importO
    bjectManager, Boolean isParentSystemObject)
    at Microsoft.SharePoint.Deployment.ContentTypeSerializer.ProcessContentType(SPContentType sourceContentType, String contentTypeXml,
    ImportObjectManager importObjectManager, Boolean IsParentSystemObject)
    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()
    Progress: Import Completed.
    Finish Time: 4/30/2011 10:42:43 PM.
    Completed with 0 warnings.
    Completed with 1 errors.

  7. If you use gl-copylistitem and reference the folder by id will it have the same end result as the gl-importlistfolder and gl-exportlistfolder? I just used it to copy a folder with one item in it by referencing the id of the folder and it apeard to work.

  8. I am running into same issue. I got 0 errors and warning but there is nothing in the new directory. I did noticed files in old directory have newer timestamp. Any idea?

  9. Can I use gl-exportlistfolder from SharePoint 2007 and then gl-importlistfolder into SharePoint 2010?


Leave a comment

CAPTCHA Image

*

No trackbacks yet.