From 5194dc0198491addceb636145d9fe72305ff2111 Mon Sep 17 00:00:00 2001 From: "Bobby Abellana (aider)" Date: Fri, 21 Feb 2025 09:26:32 -0800 Subject: [PATCH] fix: URL encode folder path in List-XlsFiles function --- SharePointFunctions.ps1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/SharePointFunctions.ps1 b/SharePointFunctions.ps1 index 37cfb35..30bd1ce 100644 --- a/SharePointFunctions.ps1 +++ b/SharePointFunctions.ps1 @@ -72,8 +72,12 @@ function List-XlsFiles { # Get the folder ID first # Construct the correct URI for the folder # Remove the /sites/tax/Shared Documents part from the folder path - $relativePath = $folderPath.Replace("/sites/tax/Shared Documents/", "") - $folderUri = "https://graph.microsoft.com/v1.0/drives/$($drive.Id)/root:$($relativePath)" + $relativePath = $folderPath.Replace("/sites/tax/Shared Documents/", "").TrimStart("/") + + # URL encode the relative path + $encodedPath = [System.Web.HttpUtility]::UrlEncode($relativePath) + + $folderUri = "https://graph.microsoft.com/v1.0/drives/$($drive.Id)/root:/$encodedPath" $script:txtStatus.Text += "Folder URI: $folderUri`n" try { $folderItem = Invoke-MgGraphRequest -Method GET -Uri $folderUri -ErrorAction Stop