1

I there anyway to output the files of a specific folder in a document library?

Listing them will be like

foreach $file in $folder.files
{
    write-host $file.name
} 

But how do I tell it to look a specific folder? In CSOM please Tried the below answer but it did not work

  • Use http://site/_api/web/getfolderbyserverrelativeurl('folder url') /files. – Akhoy Aug 1 '15 at 10:01
1

Below PowerShell script gets files from the given folder recursively:

Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Function IterateFolderRecurresive([Microsoft.SharePoint.Client.Folder] $fld,     [Microsoft.SharePoint.Client.ClientContext] $ctx)
{
Write-Host "Files from " $fld.Name
$files = $fld.Files
$ctx.Load($fld.Files)
$ctx.Load($fld.Folders)
$ctx.ExecuteQuery()
foreach($file in $files)
{

    Write-Host $file.Name
}

foreach($subFolder in $fld.Folders)
{
    IterateFolderRecurresive $subFolder $ctx
}

}

$webUrl = Read-Host "Enter your web Url"
#Start Url from relative to Document Library
$folderRelativeUrl ="Documents/Folder2.0/" 
$password = Read-Host -Prompt "Enter password" -AsSecureString 
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl) 
$credentials = New-Object System.Net.NetworkCredential("[UserName]",   $password) 
$ctx.Credentials = $credentials
$web = $ctx.Web 
$ctx.Load($web)
$ctx.ExecuteQuery()

$folder = $web.GetFolderByServerRelativeUrl($web.ServerRelativeUrl + $folderRelativeUrl)
$ctx.Load($folder)
$ctx.ExecuteQuery()

IterateFolderRecurresive $folder $ctx

Hope it will help to you..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.