Download files from Content Database

Problem

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

Pre-conditions

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.

Solution

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)
}
Advertisements

SharePoint Designer 2010 does not open site

Problem:

When attempting to open a site, SPD 2010 gives a plain error “Cannot open site” with details like

response code = “”, status = OK.

Solution:

Make sure the following tag is in the web.config of the relevant site:

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled=”true” />
</system.serviceModel>

I had accidentally removed it and spent an hour figuring out what went wrong.