Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2495 - changed default checkin to minor version and added parameter #2806

Merged
merged 4 commits into from
Feb 15, 2023
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 @@ -38,6 +38,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `-IsVivaConnectionsDefaultStartForCompanyPortalSiteEnabled` parameter to `Get-PnPHomeSite` which returns information on whether Viva Connections landing experience is set to the SharePoint home site. [#2779](https://github.com/pnp/powershell/pull/2779)
- Added `-VivaConnectionsDefaultStart` parameter to `Set-PnPHomeSite` which sets the home site to the provided site collection url and keeps the Viva Connections landing experience to the SharePoint home site. [#2779](https://github.com/pnp/powershell/pull/2779)
- Added `-LargeList` parameter to `Remove-PnPList` cmdlet which improves the list recycling experience for Lists containing huge number of items. [#2778](https://github.com/pnp/powershell/pull/2778)
- Added `-CheckinType` parameter to `Add-PnPFile` cmdlet which provides the option to specify the checkin type for a file. The default value is set to `MinorCheckIn`. [#2806](https://github.com/pnp/powershell/pull/2806)
- Added `-ApplicationId` as alias for `-ClientId` in `Connect-PnPOnline` and `Request-PnPAccessToken` cmdlets.

### Changed
Expand All @@ -53,6 +54,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Properties of `Get-PnPAzureADServicePrincipal` are now all typed instead of some of them returning unparsed JSON fragments. [#2717](https://github.com/pnp/powershell/pull/2717)
- Marked `Get-PnPSubscribeSharePointNewsDigest` and `Set-PnPSubscribeSharePointNewsDigest` as obsolete as the implementation behind these features has been changed in SharePoint Online causing them no longer to work. At present, there's no alternative for this that we can call into thus we will have to remove these in a future version. [#2720](https://github.com/pnp/powershell/pull/2720)
- Changed `Add-PnPTeamsChannel` to no longer require an `-OwnerUPN` to be provided when specifying `-ChannelType Standard` [#2786](https://github.com/pnp/powershell/pull/2786)
- Changed `Add-PnPFile` by default to upload a file as a draft with a minor version now instead of publishing it as a major version. `-CheckinType MajorCheckIn` can be used to still upload the file as a major published version [#2806](https://github.com/pnp/powershell/pull/2806)

### Removed

Expand Down
20 changes: 17 additions & 3 deletions documentation/Add-PnPFile.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ Uploads a file to Web

### Upload file
```powershell
Add-PnPFile -Path <String> -Folder <FolderPipeBind> [-NewFileName <String>] [-Checkout] [-CheckInComment <String>]
Add-PnPFile -Path <String> -Folder <FolderPipeBind> [-NewFileName <String>] [-Checkout] [-CheckInComment <String>] [-CheckinType <CheckinType>]
[-Approve] [-ApproveComment <String>] [-Publish] [-PublishComment <String>] [-UseWebDav] [-Values <Hashtable>]
[-ContentType <ContentTypePipeBind>] [-Connection <PnPConnection>] [<CommonParameters>]
```

### Upload file from stream
```powershell
Add-PnPFile -Folder <FolderPipeBind> -FileName <String> -Stream <Stream> [-Checkout] [-CheckInComment <String>]
Add-PnPFile -Folder <FolderPipeBind> -FileName <String> -Stream <Stream> [-Checkout] [-CheckInComment <String>] [-CheckinType <CheckinType>]
[-Approve] [-ApproveComment <String>] [-Publish] [-PublishComment <String>] [-UseWebDav] [-Values <Hashtable>]
[-ContentType <ContentTypePipeBind>] [-Connection <PnPConnection>] [<CommonParameters>]
```

### Create or update file from text
```powershell
Add-PnPFile -Folder <FolderPipeBind> -FileName <String> -Content <text> [-Checkout] [-CheckInComment <String>]
Add-PnPFile -Folder <FolderPipeBind> -FileName <String> -Content <text> [-Checkout] [-CheckInComment <String>] [-CheckinType <CheckinType>]
[-Approve] [-ApproveComment <String>] [-Publish] [-PublishComment <String>] [-UseWebDav] [-Values <Hashtable>]
[-ContentType <ContentTypePipeBind>] [-Connection <PnPConnection>] [<CommonParameters>]
```
Expand Down Expand Up @@ -140,6 +140,20 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -CheckinType
Specifies the type of check-in for a file.

```yaml
Type: Enum (Microsoft.SharePoint.Client.CheckinType)
Parameter Sets: (All)

Required: False
Position: Named
Default value: MinorCheckIn
Accept pipeline input: False
Accept wildcard characters: False
```

### -Checkout
If versioning is enabled, this will check out the file first if it exists, upload the file, then check it in again

Expand Down
10 changes: 7 additions & 3 deletions src/Commands/Files/AddFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class AddFile : PnPWebCmdlet
[Parameter(Mandatory = false)]
public string CheckInComment = string.Empty;

[Parameter(Mandatory = false)]
public CheckinType CheckinType = CheckinType.MinorCheckIn;

[Parameter(Mandatory = false)]
public SwitchParameter Approve;

Expand Down Expand Up @@ -117,7 +120,7 @@ protected override void ExecuteCmdlet()
{ // Swallow exception, file does not exist
}
}

Microsoft.SharePoint.Client.File file;
switch (ParameterSetName)
{
Expand Down Expand Up @@ -161,9 +164,10 @@ protected override void ExecuteCmdlet()
{
item.UpdateOverwriteVersion();
}

if (Checkout)
{
CurrentWeb.CheckInFile(fileUrl, CheckinType.MajorCheckIn, CheckInComment);
CurrentWeb.CheckInFile(fileUrl, CheckinType, CheckInComment);
}

if (Publish)
Expand Down Expand Up @@ -197,7 +201,7 @@ protected override void ExecuteCmdlet()
private Folder EnsureFolder()
{
// First try to get the folder if it exists already. This avoids an Access Denied exception if the current user doesn't have Full Control access at Web level
CurrentWeb.EnsureProperty(w => w.ServerRelativeUrl);
CurrentWeb.EnsureProperty(w => w.ServerRelativeUrl);

Folder folder = null;
try
Expand Down