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

For SPO, we can add AddSubFolderUsingPath method: #1340

Closed
yogendermanral opened this issue Aug 24, 2020 · 1 comment · Fixed by #1353
Closed

For SPO, we can add AddSubFolderUsingPath method: #1340

yogendermanral opened this issue Aug 24, 2020 · 1 comment · Fixed by #1353

Comments

@yogendermanral
Copy link

For SPO, we can add AddSubFolderUsingPath method:

/_api/web/GetFolderByServerRelativePath(DecodedUrl=@a1)/AddSubFolderUsingPath(DecodedUrl=@a2)?@a1=...&@a2=...

It can create a folder item in one call in a subfolder. Even now this endpoint can be used with the help of SPHttpClient. The method is rather simple, it's a POST with 2 params: the first one stands for folder relative url, where to create, the second one is FileLeafRef/Title of a folder to create.

For non-modern API this can be used:

const list = sp.web.lists.getByTitle('ListA');
const folderName = 'My subfolder';
const rootFolder = 'Folder 1/Folder 2';
list.items.add({
  Title: Util.getGUID(),
  // The folder is created in a root, so create it first with a temp unique name
  FileSystemObjectType: 1,
  ContentTypeId: '0x0120'
  // FileLeafRef unfortunately is ignored while creation
}).then(({ item }) => {
  return item.update({
    Title: folderName, // Rename the folder name
    FileLeafRef: `${rootFolder}/${folderName}` // Move to a subfolder
  });
}).then(console.log);

Originally posted by @koltyakov in #100 (comment)

@github-actions
Copy link

This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants