Hi,
Is there any way we can create folders and sub folders inside Generic List?
Hi @jsuhail1988 - well, yes and no. You can create the folder and it will be there BUT it will not behave like a real folder. You can however see this answer for a workaround that uses /_vti_bin/listdata.svc/. Thanks for your interest in the library.
Edit: Also found this from Rob - perhaps we can patch the library to handle it. Will have to investigate.
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);
Closing as answered.
const web = Web(context.pageContext.web.absoluteUrl);
const list = web.lists.getByTitle('Test');
const folderName = 7;
const rootFolder = 10;
list.items.add({
Title: folderName,
// 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 }) => {
// var v = item;
return item.update({
Title: folderName, // Rename the folder name
FileLeafRef: `${rootFolder}/${folderName}` // Move to a subfolder
});
})
Not working for me
Most helpful comment
Closing as answered.