Rojin
Rojin

Reputation: 19

Retrieve Files from a folder with special Character(%) with CAML query in sharepoint

I Have folder (ABC%ABC) in sharepoint, I want to retrieve all the files from the specific folder.

Upvotes: 0

Views: 280

Answers (1)

Emily Du - MSFT
Emily Du - MSFT

Reputation: 628

You could run following PowerShell.

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
Function Get-FilesFromFolder()
{
    param
    (
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $FolderURL
    )
    Try {
        #Setup Credentials to connect
        $Cred = Get-Credential
        $Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
     
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Cred
 
        #Get the Folder and Files
        $Folder=$Ctx.Web.GetFolderByServerRelativeUrl($FolderURL)
        $Ctx.Load($Folder)
        $Ctx.Load($Folder.Files)
        $Ctx.ExecuteQuery()
 
        #Iterate through each File in the folder
        Foreach($File in $Folder.Files)
        {
            #Get Name for each File
            Write-Host $File.Name
        }
    }
    Catch {
        write-host -f Red "Error Getting Files from Folder!" $_.Exception.Message
    }
}
    
#Set Parameter Values
$SiteURL="https://crescent.sharepoint.com/sites/marketing"
$FolderURL="/Branding/Classified/Finance Department Files"
 
#Call the function to get list items from folder
Get-FilesFromFolder -SiteURL $SiteURL -FolderURL $FolderURL

Upvotes: 1

Related Questions