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

[FEATURE] Added the Folder parameter to Add-PnPDocumentSet #4029

Merged
merged 3 commits into from
Aug 9, 2024
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
23 changes: 21 additions & 2 deletions documentation/Add-PnPDocumentSet.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Creates a new document set in a library.
## SYNTAX

```powershell
Add-PnPDocumentSet -List <ListPipeBind> -Name <String> -ContentType <ContentTypePipeBind>
Add-PnPDocumentSet [-List] <ListPipeBind> [-Name] <String> [-ContentType <ContentTypePipeBind>] [-Folder <String>]
[-Connection <PnPConnection>]
```

Expand All @@ -29,7 +29,12 @@ Allows to add new document set to library.
Add-PnPDocumentSet -List "Documents" -ContentType "Test Document Set" -Name "Test"
```

This will add a new document set based upon the 'Test Document Set' content type to a list called 'Documents'. The document set will be named 'Test'
### EXAMPLE 2
```powershell
Add-PnPDocumentSet -List "Documents" -ContentType "Test Document Set" -Name "Test" -Folder "Projects/Europe"
```

This will add a new document set based upon the 'Test Document Set' content type to a list called 'Documents'. The document set will be named 'Test' and will be added to the 'Europe' folder which is located in the 'Projects' folder. Folders will be created if needed.

## PARAMETERS

Expand Down Expand Up @@ -60,6 +65,20 @@ Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Folder

The list relative URL of a folder. E.g. "MyFolder" for a folder located in the root of the list, or "MyFolder/SubFolder" for a folder located in the MyFolder folder which is located in the root of the list.

```yaml
Type: String
Parameter Sets: (All)

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

### -List
The name of the list, its ID or an actual list object from where the document set needs to be added
Expand Down
13 changes: 12 additions & 1 deletion src/Commands/DocumentSets/AddDocumentSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class AddDocumentSet : PnPWebCmdlet
[ValidateNotNullOrEmpty]
public string Name;

[Parameter(Mandatory = false)]
public string Folder;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please modify this to use FolderPipeBind ? You can check & copy over the implementation that we have in Add-PnPFolder cmdlet, would make things easier and consistent for users

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @gautamdsheth I can update this, however I used the logic in Add-PnPListItem which will create the folder if it doesn't exist. It also uses the relative path from the List.RootFolder e.g. "Folder A/Folder B" as in this command we are specifying the List already which makes sense rather than having to repeat the List name/path in the FolderPipeBand e.g. "Shared Documents/Folder A/Folder B"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielcecil - will merge it and make some changes later. The advantage of pipebind is that we can easily use it with Get-PnPFolder or related cmdlets. If you notice the code, it does create the folder if it doesn't exist in that cmdlet.


[Parameter(Mandatory = true)]
[ValidateNotNullOrEmpty]
public ContentTypePipeBind ContentType;
Expand All @@ -42,8 +45,16 @@ protected override void ExecuteCmdlet()
throw new PSArgumentException($"Content type '{ContentType}' does not inherit from the base Document Set content type. Document Set content type IDs start with 0x120D520");
}

var targetFolder = list.RootFolder;

if (Folder != null)
{
// Create the folder if it doesn't exist
targetFolder = CurrentWeb.EnsureFolder(list.RootFolder, Folder);
}

// Create the document set
var result = DocumentSet.Create(ClientContext, list.RootFolder, Name, listContentType.Id);
var result = DocumentSet.Create(ClientContext, targetFolder, Name, listContentType.Id);
ClientContext.ExecuteQueryRetry();

WriteObject(result.Value);
Expand Down
Loading