Skip to content

Creating Document Sets in a library #1419

Answered by rlv-dan
rlv-dan asked this question in Q&A
Discussion options

You must be logged in to vote

Ok, here is how I solved it:

// Create a new folder
var list = await context.Web.Lists.GetByServerRelativeUrlAsync($"{context.Uri.PathAndQuery}/MyLibrary");
var folder = await list.RootFolder.EnsureFolderAsync("My Doc Set");

// Fetch the *list item* of the folder
await folder.ListItemAllFields.LoadAsync();
var listItem = await list.Items.GetByIdAsync(folder.ListItemAllFields.Id);

// Change the content type to one based on Document Set CT (= starts with 0x0120D520)
listItem["ContentTypeId"] = "0x0120D520005E02181D34C74530B814E626B873E036";
// Set shared fields
listItem["MySharedField"] = "123";
await listItem.UpdateAsync();

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by jansenbe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants