I would like to add a button that appears on a SPO Modern Document Library that states "Create a new folder structure". (see below image).

enter image description here

When clicked I would like that button to:

  1. Prompt the user to enter a Name and hit OK.
  2. Create a pre-defined folder structure of multiple sub-folders where the top-most folder is the name they entered in the above step.

E.g. the end outcome is a folder structure as below.

  • "My Folder Name I entered"
    • Sub-Folder 1
      • Sub-Sub-Folder 1.1
      • Sub-Sub-Folder 1.2
    • Sub-Folder 2
      • Sub-Sub-Folder 2.1
    • Sub-Folder 3

I'm not quite sure where to even start...How might I go about achieving this from a no-code and code perspective..?

Could this be achieved with a combination of Flow + PowerApps?


If I go down the path of SPFx, is there any good starting point examples that someone could point me to build from?

p.s: I'm aware of Document Sets and creating a Folder that is copy and pasted as solutions, however I'm more interested in something custom.


2 Answers 2


Below is what you need to do.

  • Create SPFx extension of type List View Command Set
  • Location of Command set should be set to ClientSideExtension.ListViewCommandSet.CommandBar
  • Use OnExecute Method to prompt dialog which take inputs from user as folder name
  • Use REST API to create Folder and subfolders as per your requirement

Below are reference links to get started

  • Create your SPFx extension using this link
  • Use OnExecute method provided in this sample
  • Using rest api to create folder follow this link

Below is sample onExecute method to use

    public onExecute(event: IListViewCommandSetExecuteEventParameters): void {
      switch (event.itemId) {
        case 'COMMAND_1':
          Dialog.alert(`Clicked ${strings.Command1}`);
        case 'COMMAND_2':
          Dialog.prompt(`Clicked ${strings.Command2}. Enter something to alert:`).then((value: string) => {

          throw new Error('Unknown command');

Hope this helps..


You can actually do this with Flow and PowerApps (except no button in the actual library)

1) Create a PowerApps some thing like: enter image description here

1.1) Trigger the Flow(You can disable the button after it is click and other validation as needed) enter image description here

2) Create a folder with a txt file (which can be deleted after structure is created) and folder structure will be ensured by SharePoint enter image description here

3) SharePoint Library - Folder Structure enter image description here

  • A couple follow-up questions. (1) Will this work in my situation as I have multiple Folders and Sub-Folders, 5 Folders in total with each one have 2-10 Sub-Folders. (2) How can I trigger the PowerApps form ? it doesn't necessarily need to be a button from the Document Library, can be a Quick Link web part or something accessible from the Homepage of the Team Site.
    – Ushka
    Commented Jun 19, 2019 at 20:09
  • Well I think this is what my Flow answer is doing, take the first name of the Folder and Create all sub-folders structure it doesn't matter how many sub folders. You can just create the sub folder structure you want in the compose action. 2) Like I am doing, go to PowerApps and create Flow. I will edit my answer a bit Commented Jun 19, 2019 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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