Download files from Content Database


Compare master page content from two content databases, modified independently.


In a SharePoint migration project, was in a situation where the content of the application in two diffrent servers (say dev vs test) had changed independently. In other words, dev cdb was modified, so was the test cdb. And both changes were almost valid. I had to individually pick and choose changes from dev and test and merge into a single source. And there were several such files.

SharePoint Designer 2010 exibhits a Vedantic property of being the best, not-so-best and neither both all at the sametime. In other words, the goodness in you can never the triumph the evil of SPD and will eternally continue to fight with it.

Modifying each file and merging would be cumbersome, especially when SPD usually likes to mind its own business when you want it to respond. So I decided to download the files from both content databases locally, then use a sophisticated compare tool like Beyond Compare or WinMerge, merge them and upload it back to the content database.


Microsoft must have finally shed some sense of shame and hired a few Unix guys who probably are behind PowerShell. So here comes PowerShell again to the rescue to do that effortlessly.

$url = "http://yoursite"
$masterPageGallery = "/_catalogs/masterpage"
$destPath = "c:/site1"
$site = Get-SPSite($url)
$webs = $site.AllWebs
$rootWeb = $site.RootWeb
#Get the MasterPageGallery folder
#Another way to get MPG is $rootWeb.GetCatalog(116)
$folder = $rootWeb.GetFolder($masterPageGallery)
$files = $folder.Files
foreach ($f in $files) {
 [Byte[]] $fBytes = $f.OpenBinary()
 #Store the name explicitly for creating DestPath;
# by default $f := $f.Url, not $f.Name
 $fileName = $f.Name
 $destFile = "$destPath/$fileName"
 [System.IO.File]::WriteAllBytes($destFile, $fBytes)

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: