Skip to content

Commit f3c79fd

Browse files
authored
Merge pull request #4480 from koskila/fix/4370
Fixes #4370 by changing absolute URLs to relative
2 parents 57a45cf + 68a54ff commit f3c79fd

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
5151
- All Power Platform cmdlets no longer require an environment to be specified. If omitted, the default environment will be retrieved and used. [#4415](https://github.com/pnp/powershell/pull/4415)
5252
- When passing in an existing connection using `-Connection` on `Connect-PnPOnline`, the clientid from the passed in connection will be used for the new connection [#4425](https://github.com/pnp/powershell/pull/4425)
5353
- Removed `-Confirm` parameter from `Remove-PnPUser` and `Remove-PnPAvailableSiteClassification` cmdlets. Use `-Force` instead. [#4455](https://github.com/pnp/powershell/pull/4455)
54+
- `Get-PnPFile` now also supports passing in a full SharePoint Online URL [#4480](https://github.com/pnp/powershell/pull/4480)
5455

5556
### Fixed
5657

@@ -80,6 +81,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
8081

8182
### Contributors
8283

84+
- Antti K. Koskela [koskila]
8385
- Steve Beaugé [stevebeauge]
8486
- [reusto]
8587
- Fredrik Thorild [fthorild]

documentation/Get-PnPFile.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,40 +53,47 @@ Retrieves the file and downloads it to the current folder
5353

5454
### EXAMPLE 2
5555
```powershell
56+
Get-PnPFile -Url "https://contoso.sharepoint.com/sites/project/Shared Documents/Document.docx"
57+
```
58+
59+
Retrieves the file and downloads it to the current folder
60+
61+
### EXAMPLE 3
62+
```powershell
5663
Get-PnPFile -Url /sites/project/SiteAssets/image.jpg -Path c:\temp -FileName image.jpg -AsFile
5764
```
5865

5966
Retrieves the file and downloads it to c:\temp\image.jpg
6067

61-
### EXAMPLE 3
68+
### EXAMPLE 4
6269
```powershell
6370
Get-PnPFile -Url /sites/project/_catalogs/themes/15/company.spcolor -AsString
6471
```
6572

6673
Retrieves the contents of the file as text and outputs its contents to the console
6774

68-
### EXAMPLE 4
75+
### EXAMPLE 5
6976
```powershell
7077
Get-PnPFile -Url /sites/project/Shared Documents/Folder/Presentation.pptx -AsFileObject
7178
```
7279

7380
Retrieves the file and returns it as a File object
7481

75-
### EXAMPLE 5
82+
### EXAMPLE 6
7683
```powershell
7784
Get-PnPFile -Url /sites/project/_catalogs/themes/15/company.spcolor -AsListItem
7885
```
7986

8087
Retrieves the file and returns it as a ListItem object
8188

82-
### EXAMPLE 6
89+
### EXAMPLE 7
8390
```powershell
8491
Get-PnPFile -Url /personal/john_tenant_onmicrosoft_com/Documents/Sample.xlsx -Path c:\temp -FileName Project.xlsx -AsFile
8592
```
8693

8794
Retrieves the file Sample.xlsx by its site relative URL from a OneDrive for Business site and downloads it to c:\temp\Project.xlsx
8895

89-
### EXAMPLE 7
96+
### EXAMPLE 8
9097
```powershell
9198
Get-PnPFile -Url "/sites/templates/Shared Documents/HR Site.pnp" -AsMemoryStream
9299
```
@@ -250,4 +257,4 @@ Accept wildcard characters: False
250257
251258
## RELATED LINKS
252259
253-
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
260+
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)

src/Commands/Files/GetFile.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.SharePoint.Client;
22
using PnP.Core.Model.SharePoint;
33
using PnP.Framework.Utilities;
4+
using System;
45
using System.IO;
56
using System.Management.Automation;
67
using System.Threading.Tasks;
@@ -66,6 +67,12 @@ protected override void ExecuteCmdlet()
6667
}
6768
}
6869

70+
if (Uri.IsWellFormedUriString(Url, UriKind.Absolute))
71+
{
72+
// We can't deal with absolute URLs
73+
Url = UrlUtility.MakeRelativeUrl(Url);
74+
}
75+
6976
// 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.
7077
Url = Utilities.UrlUtilities.UrlDecode(Url.Replace("+", "%2B"));
7178

0 commit comments

Comments
 (0)