Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- 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)
- 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)
- Removed `-Confirm` parameter from `Remove-PnPUser` and `Remove-PnPAvailableSiteClassification` cmdlets. Use `-Force` instead. [#4455](https://github.com/pnp/powershell/pull/4455)
- `Get-PnPFile` now also supports passing in a full SharePoint Online URL [#4480](https://github.com/pnp/powershell/pull/4480)

### Fixed

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

### Contributors

- Antti K. Koskela [koskila]
- Steve Beaugé [stevebeauge]
- [reusto]
- Fredrik Thorild [fthorild]
Expand Down
19 changes: 13 additions & 6 deletions documentation/Get-PnPFile.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,40 +53,47 @@ Retrieves the file and downloads it to the current folder

### EXAMPLE 2
```powershell
Get-PnPFile -Url "https://contoso.sharepoint.com/sites/project/Shared Documents/Document.docx"
```

Retrieves the file and downloads it to the current folder

### EXAMPLE 3
```powershell
Get-PnPFile -Url /sites/project/SiteAssets/image.jpg -Path c:\temp -FileName image.jpg -AsFile
```

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

### EXAMPLE 3
### EXAMPLE 4
```powershell
Get-PnPFile -Url /sites/project/_catalogs/themes/15/company.spcolor -AsString
```

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

### EXAMPLE 4
### EXAMPLE 5
```powershell
Get-PnPFile -Url /sites/project/Shared Documents/Folder/Presentation.pptx -AsFileObject
```

Retrieves the file and returns it as a File object

### EXAMPLE 5
### EXAMPLE 6
```powershell
Get-PnPFile -Url /sites/project/_catalogs/themes/15/company.spcolor -AsListItem
```

Retrieves the file and returns it as a ListItem object

### EXAMPLE 6
### EXAMPLE 7
```powershell
Get-PnPFile -Url /personal/john_tenant_onmicrosoft_com/Documents/Sample.xlsx -Path c:\temp -FileName Project.xlsx -AsFile
```

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

### EXAMPLE 7
### EXAMPLE 8
```powershell
Get-PnPFile -Url "/sites/templates/Shared Documents/HR Site.pnp" -AsMemoryStream
```
Expand Down Expand Up @@ -250,4 +257,4 @@ Accept wildcard characters: False

## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
7 changes: 7 additions & 0 deletions src/Commands/Files/GetFile.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.SharePoint.Client;
using PnP.Core.Model.SharePoint;
using PnP.Framework.Utilities;
using System;
using System.IO;
using System.Management.Automation;
using System.Threading.Tasks;
Expand Down Expand Up @@ -66,6 +67,12 @@ protected override void ExecuteCmdlet()
}
}

if (Uri.IsWellFormedUriString(Url, UriKind.Absolute))
{
// 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"));

Expand Down
Loading