• PowerShell Download files from a library


    # Check to ensure Microsoft.SharePoint.PowerShell is loaded
    $Snapin = get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
    if($Snapin -eq $null){
        Write-host "Loading SharePoint Powershell Snapin"
        Add-PSSnapin "Microsoft.SharePoint.Powershell"
    }
    $web = Get-SPWeb -Identity http://gdcvmg_sps01
    write-host $web
    $destination = "C:\\test2\\"
    $list = $web.GetList("document lib test2")
    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)
    }
    

      

  • 相关阅读:
    OpenGL完整实例
    OpenGL
    Socket(2)
    Socket(1)
    Stream,Reader/Writer,Buffered的区别(2)
    Stream,Reader/Writer,Buffered的区别(1)
    SQLite数据库与Contentprovider(2)
    SQLite数据库与Contentprovider(1)
    数据存储和访问
    AIDL与service
  • 原文地址:https://www.cnblogs.com/ilawrence/p/2889301.html
Copyright © 2020-2023  润新知