powershell icon indicating copy to clipboard operation
powershell copied to clipboard

[BUG] Get-PnPFile incorrectly interprets %20 as a space in the file name

Open ninos-logic opened this issue 8 months ago • 2 comments

Reporting an Issue or Missing Feature

Bug
Get-PnPFile appears to interpret %20 as a space even when %20 is meant to be part of a literal file name, not URL encoding.


Expected Behavior

Using Get-PnPFile with a file URL that contains %20 (as part of the actual filename) should successfully retrieve the file without automatically decoding %20 into a space. For example:

Get-PnPFile -Url "Shared Documents/test%20file.txt" -Path . -FileName "output.txt"

This should download the file test%20file.txt from SharePoint.

Actual Behavior

Get-PnPFile interprets %20 as a space, so it searches for a file named test file.txt. This results in a “file not found” error when the actual filename contains %20 literally:

Get-PnPFile : File not found: Shared Documents/test file.txt

Steps to Reproduce

  1. Upload a file named test%20file.txt to a SharePoint document library (e.g., “Shared Documents”).
  2. On a Linux environment (e.g., Ubuntu 22.04), run:
Get-PnPFile -Url "Shared Documents/test%20file.txt" -Path . -FileName "output.txt"
  1. Observe the error indicating the file cannot be found.

Version of PnP.PowerShell Module

Run:

Get-Module -Name "PnP.PowerShell" -ListAvailable

and paste the output here.

Operating System / Environment

  • [x] Linux (e.g., Ubuntu 22.04)
  • [ ] Windows
  • [ ] macOS
  • [ ] Azure Cloud Shell
  • [ ] Azure Functions
  • [ ] Other: __________

Notes

It appears that the -Url parameter in Get-PnPFile is URL-decoded automatically, even when %20 is intended as a literal part of the filename. This behavior makes it impossible to retrieve files whose names contain literal %20 sequences unless they are renamed. If this behavior is intentional, please consider adding a flag or bypass option to prevent automatic decoding.

ninos-logic avatar Jul 11 '25 12:07 ninos-logic

Had a look at the code for this. The %20 in particular is really tricky to have in the filename. There are several layers in the code that will filter it out and even avoid the bypass option to use %2520 will be taken out. I don't see a way to fix this in the code without making things really ugly. I know it's not ideal from the end user perspective, but do you really have to use %20 in your filenames? Anything else basically would work, just not %20.

KoenZomers avatar Aug 21 '25 01:08 KoenZomers

It's not about wanting to use %20 in file names, but rather about ending up with file names that contain %20 . This can happen when using migration tools to move files into SharePoint. In my case, for example, we migrated from Dropbox to SharePoint, and suddenly some file names contained %20 instead of spaces. If SharePoint allows file names with %20 , then there should also be a way to fix or normalize them. I managed to find a workaround by scanning all files that contain %20 and renaming them by replacing %20 with a space. After that, I was able to download the files using PnP, which worked, but it's not intuitive and requires scripting skills

ninos-logic avatar Aug 25 '25 11:08 ninos-logic