Download whole files from document library

Normally when downloading all the files from SharePoint Document library, we use ‘Open with Explorer’ and just drag and drop to specific driver.

However if the file counts are over the list threshold limit, you can’t open the ‘open with explorer’ with errors.

Of course you can increase the threshold limit but how about just use powershell script to download all the files include folders.

This is originally from the blog : http://blogs.msdn.com/b/varun_malhotra/archive/2012/02/13/10265370.aspx

$destination = “F:\\test”
$webUrl = “https://aaa”
$listUrl = “https://aaa/CardDocs”
##############################################################

$web = Get-SPWeb -Identity $webUrl
$list = $web.GetList($listUrl)

function ProcessFolder {
param($folderUrl)
$folder = $web.GetFolder($folderUrl)
foreach ($file in $folder.Files) {
#Ensure destination directory
$destinationfolder = $destination + “/” + $folder.Url
if (!(Test-Path -path $destinationfolder))
{
$dest = New-Item $destinationfolder -type directory
}
#Download file
$binary = $file.OpenBinary()
$stream = New-Object System.IO.FileStream($destinationfolder + “/” + $file.Name), Create
$writer = New-Object System.IO.BinaryWriter($stream)
$writer.write($binary)
$writer.Close()
}
}

#Download root files
ProcessFolder($list.RootFolder.Url)
#Download files in folders
foreach ($folder in $list.Folders) {
ProcessFolder($folder.Url)
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: