diff --git a/documentation/Get-PnPFile.md b/documentation/Get-PnPFile.md index a4f6d0a8e..cebdb6ee8 100644 --- a/documentation/Get-PnPFile.md +++ b/documentation/Get-PnPFile.md @@ -39,6 +39,12 @@ Get-PnPFile -Url -AsString [-Connection ] Get-PnPFile -Url -AsMemoryStream [-Connection ] ``` +### Skip decoding of file name, for instance %20 used in file name +```powershell +Get-PnPFile -Url -NoUrlDecode [-Connection ] +``` + + ## DESCRIPTION Allows downloading of a file from SharePoint Online. The file contents can either be read directly into memory as text, directly saved to local disk or stored in memory for further processing. @@ -100,6 +106,13 @@ Get-PnPFile -Url "/sites/templates/Shared Documents/HR Site.pnp" -AsMemoryStream Retrieves the file in memory for further processing +### EXAMPLE 9 +```powershell +Get-PnPFile -Url "Shared Documents/test%20file.docx" -NoUrlDecode +``` + +Retrieves the file without Url decoding for further processing + ## PARAMETERS ### -AsFile @@ -255,6 +268,19 @@ Accept pipeline input: True (ByValue) Accept wildcard characters: False ``` +### -NoUrlDecode + +```yaml +Type: SwitchParameter +Parameter Sets: (All) + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ## RELATED LINKS [Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) \ No newline at end of file diff --git a/src/Commands/Files/GetFile.cs b/src/Commands/Files/GetFile.cs index 4a7495d03..158fe4701 100644 --- a/src/Commands/Files/GetFile.cs +++ b/src/Commands/Files/GetFile.cs @@ -52,6 +52,9 @@ public class GetFile : PnPWebCmdlet [Parameter(Mandatory = false, ParameterSetName = URLASMEMORYSTREAM)] public SwitchParameter AsMemoryStream; + [Parameter(Mandatory = false)] + public SwitchParameter NoUrlDecode; + protected override void ExecuteCmdlet() { var serverRelativeUrl = string.Empty; @@ -72,9 +75,12 @@ protected override void ExecuteCmdlet() // We can't deal with absolute URLs Url = UrlUtility.MakeRelativeUrl(Url); } - + // Remove URL decoding from the Url as that will not work. We will encode the + character specifically, because if that is part of the filename, it needs to stay and not be decoded. - Url = Utilities.UrlUtilities.UrlDecode(Url.Replace("+", "%2B")); + if (!NoUrlDecode) + { + Url = Utilities.UrlUtilities.UrlDecode(Url.Replace("+", "%2B")); + } var webUrl = CurrentWeb.EnsureProperty(w => w.ServerRelativeUrl);