Skip to content

Commit

Permalink
Merge pull request #2806 from gautamdsheth/bugfix/2495
Browse files Browse the repository at this point in the history
Fix #2495 - changed default checkin to minor version and added parameter
  • Loading branch information
KoenZomers authored Feb 15, 2023
2 parents 641f2c0 + 0f63d1a commit 49f8534
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
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

0 comments on commit 49f8534

Please sign in to comment.