Online Training On SharePoint

Wednesday, 21 July 2010

Exporting Document Set as Zip file using Power Shell Script

SharePoint 2010 has a new feature called Document Set. Each Document Set can consist of multiple files. There is no functionality available on SharePoint UI where we can export all these files from a DocSet into a zip file. This can be achieved using Windows PowerShell Script. Here is the Script to achieve the same:

$docsettitle = $args[0]
if($args.length -eq 1)
    $maxSizeAllowed = 1000 ## ~ 1 GB
    $maxSizeAllowed = $args[1]
$web = Get-SPWeb http://localhost
$list = $web.Lists["TestLib"]
$rootFolder = $list.RootFolder
$docset = $null
foreach($docsetFolder in $rootFolder.SubFolders)
        $docset = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::GetDocumentSet($docsetFolder)
$zipFilePath = "C:\" + $docsettitle + ".zip"
$stream = New-Object System.IO.FileStream($zipFilePath, [System.IO.FileMode]::Create);
$docset.Export($stream, $maxSizeAllowed)
Post a Comment
Related Posts with Thumbnails