Content Export in Sharepoint 2007

Sometimes, looking at an object model and all the options available can get you into trouble.

This happened with me while trying to figure out how to export content from a Sharepoint publishing site.  I was hoping to download information from one of our production sites and move it to a local development environment so that I can run multiple tests for a bug that I was researching.  However, I learned a few things about the Content Deployment namespace in Sharepoint.

I started off my research by reviewing the Microsoft.SharePoint.Deployment.SPExport and the Microsoft.SharePoint.Deployment.SPExportSettings classes.  I was working through the various properties that I would need to set to accomplish my goals.

$url = "http://testsite/"
$filelocation = 'c:\temp\export'
$ExportSettings = New-Object Microsoft.SharePoint.Deployment.SPExportSettings
$ExportSettings.AutoGenerateDataFileName = $true
$ExportSettings.BaseFileName = "testsite.cmp"
$ExportSettings.CommandLineVerbose = $true
$ExportSettings.ExportMethod = [Microsoft.SharePoint.Deployment.SPExportMethodType]::ExportAll
$ExportSettings.FileCompression = $true;
$ExportSettings.FileMaxSize = [Int32]::MaxValue
$ExportSettings.IncludeSecurity = [Microsoft.SharePoint.Deployment.SPIncludeSecurity]::All
$ExportSettings.IncludeVersions = [Microsoft.SharePoint.Deployment.SPIncludeVersions]::CurrentVersion
$ExportSettings.LogFilePath = 'c:\temp\export\log.txt'
$ExportSettings.OverwriteExistingDataFile = $true
$ExportSettings.SiteUrl = $url
$ExportSettings.FileLocation = $filelocation
$ExportSettings.Validate()

$Export = New-Object Microsoft.SharePoint.Deployment.SPExport($ExportSettings)
$Export.Run()

This seems pretty straightforward.  After running the code above, I had no errors.  Seemed pretty good to me, so I go to my file location (C:\Temp\Export) and…NOTHING!

Since I am running this in PowerGUI for testing, I can look back at the variables and I see that the $Export.Settings.FileLocation property has some “temp” location.  (C:\Documents and Settings\\Local Settings\Temp\1\{Some GUID}).  I open that location and find that the files I need are there.  Why didn’t they move to the C:\temp\export folder like I specified?

As it turns out, there is an AutoGenerateDataFileName property that I had set to “true.”  I should not have even messed with this property, because it is “false” by default.  I tested this setting as “true” and “false” on a couple of runs and found that when it is “false,” the files showed up in the C:\temp\export folder like I wanted.

Moral of the story is that “less is more!”  Don’t mess with object properties unless you are sure you need them set!

Hope this saves someone some time.

This entry was posted in Scripting, Sharepoint 2007 and tagged , , , , , , , , . Bookmark the permalink.

1 Response to Content Export in Sharepoint 2007

  1. Ryan Dennis says:

    Reblogged this on sharepointryan.com and commented:
    Great post on Content Export in SharePoint 2007 by Jon Tyler!

Comments are closed.