Download complete folders in SharePoint on-premise?

Tevon2.0 1,101 Reputation points
2023-06-05T12:49:47.47+00:00

Greetings,

I am seeking to attain the ability to download a folder to my local drive once users finish uploading specific files into their designated folders. However, I do not see the option in SharePoint 2019 to download folders, only files. Is there recommended a method of accomplishing this? (I would like to set this up for use without SharePoint Designer.)

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
2,227 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,575 questions
SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,809 questions
0 comments No comments
{count} votes

Accepted answer
  1. Haoyan Xue_MSFT 19,871 Reputation points Microsoft Vendor
    2023-06-07T01:39:36.5933333+00:00

    Hi @Tevon2.0 ,

    Ok, here are the detailed steps:

    1. First, you need to determine the url of the subfolder you want to download.

    User's image

    2.You need to replace SharePointFolderUrl(The url obtained in the first step) and Path(the local address you want to save to) in the last line of code: Download-Folder -SharePointFolderUrl "http://sp19/sites/luyi19/Shared Documents/folder1" -Path "C:\SP" -Recurse -Verbose

    3.Just run the powershell code in SharePoint 2019 Management Shell.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Haoyan Xue_MSFT 19,871 Reputation points Microsoft Vendor
    2023-06-06T03:19:01.2066667+00:00

    Hi @Tevon2.0 ,

    By design, Folders and Sub-folders can not support the OOTB "Download a Copy" feature.

    As a workaround, you can download specific folders using powershell (You need to replace SharePointFolderUrl and LocalFolderPath in the last line of code).

    The url of a specific folder/subfolder can be viewed by the end of the URL of the page(%2F = Forward slash (/), %20= Forward slash (Space)), for example:

    User's image

    Add-PSSnapin Microsoft.Sharepoint.PowerShell
    
    function Download-Folder
    {
        [CmdletBinding()]
        param
        (
            [Parameter(Mandatory=$true)][string]$SharePointFolderUrl,
            [Parameter(Mandatory=$true)][string]$Path,
            [Parameter(Mandatory=$false)][switch]$Recurse
        )
    
        begin
        {
        }
        process
        {
            $site   = New-Object Microsoft.SharePoint.SPSite($SharePointFolderUrl)
            $web    = $site.OpenWeb()
            $folder = $web.GetFolder($SharePointFolderUrl)
    
            if( $folder.Exists )
            {
                Write-Verbose "$(Get-Date) - Processing Folder: $($folder.ServerRelativeUrl)"
    
                foreach( $file in $folder.Files )
                {
                    $fileUrl = $site.MakeFullUrl($file.ServerRelativeUrl)
                
                    Write-Verbose "$(Get-Date) - Downloading File: $($fileUrl)"
    
                    $response = Invoke-WebRequest -Uri $fileUrl -UseDefaultCredentials -Verbose:$false
                    
                    try
                    {
                        # combine the provided path to the server relative url
                        $savePath = Join-Path -Path $Path -ChildPath $file.ParentFolder.ServerRelativeUrl
    
                        # ensure the folder exists
                        New-Item -Path $savePath -ItemType Directory -Force | Out-Null
    
                        # add the file name to the path
                        $savePath = Join-Path -Path $savePath -ChildPath $file.Name
                        
                        # save the bits locally
                        $stream = New-Object System.IO.FileStream( $savePath, [System.IO.FileMode]::Create, [System.IO.FileAccess]::ReadWrite)
                        $response.RawContentStream.CopyTo($stream)
                    }
                    finally
                    {
                        if( $stream ) 
                        {
                            $stream.Close()
                            $stream.Dispose()
                        }
                    }
                }
    
                if( $Recurse )
                {
                    foreach( $subFolder in $folder.SubFolders )
                    {
                        if( $subFolder.Item )
                        {
                            $subFolderUrl = $site.MakeFullUrl($subFolder.ServerRelativeUrl)
                            Download-Folder -SharePointFolderUrl $subFolderUrl -Path $Path -Recurse
                        }
                    }
                }
            }
        }
        end
        {
        }
    }
    
    Download-Folder -SharePointFolderUrl "http://sp19/sites/luyi19/Shared Documents/folder1" -Path "C:\SP" -Recurse -Verbose
    

    The download effect diagram after running is shown in the figure below (it will automatically create a local folder to store the file):User's image


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Paul de Jong 716 Reputation points
    2023-06-14T08:41:37.26+00:00

    Use scripts (see above) or use browser-based apps that provide this functionality: see link