0

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?

2

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.