How to create SharePoint Sub-Folders programmatically?
-
09-12-2020 - |
Pergunta
I want to refer to this question which shows how to create first-level folders: SharePoint Question
But I also need to know how to create Sub-Folders e.g. a Sub-Folder inside a List.
Does anyone know how to create Folders inside a List?
Solução
Try to use this
foreach (SPListItem item in list.Folders)
{
if (item.Title == "yourfoldername")
{
SPListItem newItem = list.AddItem(item.Folder.ServerRelativeUrl, SPFileSystemObjectType.Folder);
newItem["Title"] = "SubFolder";
newItem.Update();
}
}
Check the full code at Programmatically create a subfolder in SharePoint list
also you can add subfolder at specific folder by useing SPFolderCollection
as the following
SPFolderCollection Col = oList.RootFolder.SubFolders;
SPFolder Folder = Col[foldername];
SPListItem newFolder = oList.AddItem(Folder.Url, SPFileSystemObjectType.Folder, newFolderName);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange