SharePoint Create Folder in List or Document Library

In this SharePoint tutorial, we will discuss SharePoint create folder in list or document library. We will see here, how to create a folder in a SharePoint list and also steps to create a folder in SharePoint Online document library.

We will discuss different ways to create folder in SharePoint document library. We will check the below things here:

  • Why use folders in SharePoint
  • SharePoint Create folder in List
  • Can we create folders in all SharePoint Lists
  • Create Folder in SharePoint Library
  • SharePoint folder or Metadata?
  • How many folders you can create in a SharePoint document library
  • SharePoint create a folder in site pages
  • Create a folder inside SharePoint Online document library using a browser
  • How to create a folder in document library in SharePoint Online using PnP CSOM
  • Create a folder in SharePoint document library using C#
  • Create a folder in SharePoint document library using Rest API
  • Create a folder in SharePoint document library using PowerShell
  • Create a folder in SharePoint document library using JavaScript
  • Create a folder in SharePoint document library using Flow
  • Create a folder in SharePoint document library using C# CSOM

By default, folder creation is enabled in the SharePoint document library whereas in SharePoint list folder creation is disabled. Check below to enable it.

Also, we will discuss SharePoint create folder in site pages and how many folders we can create in a SharePoint document library.

I will also show you how to create a folder in SharePoint library using Rest API.

Why use folders in SharePoint

Let us first understand why to use folders in SharePoint.

Like, in Desktop we create folders to organize files, the same thing with SharePoint, we create folders in SharePoint to organize files in a SharePoint document library.

Example:

Suppose you want to create a document library to store training related documents like SharePoint development training documents, SPFx training documents, Nintex training documents or SharePoint site owner training documents.

If you will put everything in one documents library, then it will not be properly organized. Your users will find it difficult to find documents.

Now, let us see how to organize these documents in SharePoint.

Option-1:

We can create different libraries for each training course. So, in this case, there will be 4 different document libraries.

But it will be difficult to manage 4 different libraries in the SharePoint Online site.

Option-2:

Another way, we can store all the training related documents inside the SharePoint document library by creating different folders in the library.

So the SharePoint document library folder structure will looks like below:

sharepoint create folder
sharepoint create folder in document library

Similarly, if you want to organize information inside a SharePoint list we can easily create various folders in list.

Check out Enterprise Metadata and Keywords for List and Document library in SharePoint Online

SharePoint Create folder in List

By default, folder creation is disabled in a SharePoint list.

New Folder missing in SharePoint list

But we can enable list folder creation from the list settings page.

Open the SharePoint Online list and go to the list settings page.

sharepoint create folder in list

Then click on Advanced settings that is under General Settings.

Then in Folders select Yes for “Make “New Folder” command available?

how to create folder in sharepoint list

Then Save the page.

Now when you open the SharePoint List, you can see the Folder command like below:

sharepoint list create folder
sharepoint create folder in list

This is how we can enable new folder creation in SharePoint Online list.

Anytime you can click on New -> Folder to create SharePoint folder in List.

Can we create folders in all SharePoint Lists

We can use various list templates to create a list in SharePoint. But all the list templates do not support folder creation.

Below are the list templates does not support folder creation.

  • Tasks
  • Calendar
  • Discussion
  • Survey
  • Wiki

Below is a SharePoint task list, you can see in the ribbon, there is no folder creation (Folder) button. Even if you will go to the List advanced settings page, you will not see the option to enable folder creation.

sharepoint list templates not supported folder creation

Create Folder in SharePoint Library

Now, let us see how to create a folder in SharePoint document library.

In modern SharePoint library, click on New -> Folder in the command bar like below:

sharepoint create folder in document library
create folder in sharepoint library

In case you are using the SharePoint classic experience, From the ribbon, click on FILEs tab -> New Folder like below:

create folder in sharepoint online library
sharepoint create folder in document library

This is how can create folders in SharePoint library.

Create folder and subfolder in SharePoint Online document library

Let us see, first how to create a folder and subfolder in a SharePoint Online document library.

Open the SharePoint site and then Open the SharePoint document library. Then click on + New -> Folder like below:

Create a folder inside SharePoint Online document library
Create a folder inside SharePoint Online document library

Then it will ask you to provide a name in the Create a folder dialog box and then click on the Create button.

Create a folder inside SharePoint document library
Create a folder inside SharePoint document library

Then you can see the folder will be created in the SharePoint document library like below:

how to create a folder inside a document library in SharePoint
how to create a folder inside a document library in SharePoint

This is how, we can create a folder in a SharePoint document library.

If you want to create a subfolder inside the folder in the SharePoint document library, then first, open the folder in the SharePoint document library.

Then click on the + New -> Folder button like below:

Create a subfolder inside SharePoint Online document library
Create a subfolder inside SharePoint Online document library

Now, you can see here it created a subfolder inside the folder in the SharePoint document library.

Create subfolder inside SharePoint Online document library
Create subfolder inside SharePoint Online document library

This way, we can create folders and subfolders inside a document library in SharePoint Online or SharePoint 2013/2016/2019.

SharePoint folder or Metadata?

This often comes as a questions SharePoint folder or metadata?

Folders are the old way to organize documents. There are a lot of advantages of using Metadata over Folder in the SharePoint Online document library or list.

Folders inside a document library look exactly the same as we create folders in windows.

But there are a lot of disadvantages to creating folders and subfolders to store documents. It is difficult to manage documents when you have lots of nested subfolders. Also, there is a limit on the number of characters supported in a browser URL, that may create a problem when you have a long folder, subfolder, and file names.

Another disadvantage is that you may end up with duplicate documents, because you may never know you have kept the same documents in multiple folders or subfolders. Like in network drive folder structures.

Another major disadvantage of using folders is that, if you move a document from one folder to another folder, the URL of the document will be changed. So if anyone click on the document URL that you have shared previously, they will land with a file not found error.

That’s why SharePoint Metadata concept came.

Metadata is like tagging a document with the keywords according to your business requirement.

By using Metadata in SharePoint, you can easily filter, group, or sort documents by metadata. And there will not be any chance of duplicate content in the SharePoint library.

The document URL will be shorter always, if you are using metadata.

And also, you can change the metadata of a document number of times without affecting the SharePoint document URL.

So the preferences should always be given to use metadata rather folder to organize documents in a document library in SharePoint.

Check out what are document sets in SharePoint and other articles on SharePoint Document Sets Vs Folder.

You can also check how to configure metadata navigation for a document library in SharePoint Online and Create and configure metadata navigation and filtering for list or library in SharePoint Online.

How many folders you can create in a SharePoint document library

Well, how many folders we can create in a SharePoint document library? There is no direct answer to this.

According to Microsoft, you can store 30,000,000 items in a SharePoint list or documents in a SharePoint document library.

The 30 million items or documents include folders also. SharePoint treats folder as an item.

SharePoint create folder in site pages

Like list, in SharePoint site pages do not have the New Folder creation enabled. In the SharePoint site pages library, by default New folder creation is disabled. You can not see the New -> Folder option.

SharePoint create folder in site pages
SharePoint create folder in site pages missing

Like list we can enable it from the Library Advanced Settings page.

Open the SharePoint site pages library from the Site Contents page. Then click on Settings -> Library Settings.

Then click on Advanced Settings and then in Folders section, select Yes, for Make “New Folder” command available? like below:

create folder in site pages in sharepoint

Now, if you open the SharePoint site pages library, you can see the New Folder creation option like below:

create folder in sharepoint site pages
SharePoint create folder in site pages

This is how we can create folder in site pages in SharePoint Online or SharePoint 2013/2016/2019.

SharePoint create folder rest api

We can also easily create a folder in document library using SharePoint Rest API.

You can use the below Rest API code inside a script editor web part to create folder in a document library in SharePoint Online.

Below is the Rest API code to create folder in SharePoint Online document library.

<strong>Folder Name:</strong>
<input type="text" id="txtName" />
<input type="button" id="btnCreate" value="Create Folder" />
<br/>
<div id="divmessage"></div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(function () {
bindButtonClick();
});
function bindButtonClick() {
$("#btnCreate").on("click", function () {
createFolder();
});
}

function createFolder() {
var folderName = $("#txtName").val();
var siteUrl = _spPageContextInfo.webAbsoluteUrl;
var fullUrl = siteUrl + "/_api/web/folders";
$.ajax({
url: fullUrl,
type: "POST",
data: JSON.stringify({
'__metadata': { 'type': 'SP.Folder' },
'ServerRelativeUrl': 'Best Practices Documents/' + folderName
}),
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: onSuccess,
error: onFail
});
}

function onSuccess() {
$("#divmessage").html("SharePoint Folder Created Successfully !!!");
}

function onFail() {
alert('Error!');
}
</script>

Once you Save the web part page, the form will appear like below:

create folder in document library using rest api
create folder in document library using rest api

Put the folder name and click on the button “Create Folder”, the folder will be created in the document library.

SharePoint create folder rest api
SharePoint create folder rest api

This is how we can create a folder in SharePoint Online document library using Rest API.

Create folder in SharePoint document library using PnP CSOM

Let us see, how to create folders and subfolders inside SharePoint Document library Programmatically using PnP Core CSOM Library. We will also see if a folder exists inside a SharePoint document library programmatically using PnP.

If you are new to sharepoint PnP, following this article to know about PnP SharePoint Online Development using Patterns and Practices (PnP and Hide SharePoint List Title Column Programmatically using PnP CSOM.

Here, I got a requirement to create a folder and a subfolder inside a SharePoint Online document library programmatically. Here is my document library. I will create a folder and Subfolder (Inside the folder) in the “Documents” library.

create folder in sharepoint document library
create folder in sharepoint document library

The below references we have to use in the code to work with PnP libraries.

  • Microsoft.SharePoint.Client
  • OfficeDevPnP.Core

Following functions are used for creating folder in SharePoint Library.

  • FolderExists() function can be used to check folder exists or not in the SharePoint List/Document library.
  • CreateFolder() function is used to create a new folder in the Sharepoint list or document library.

Here I have created an asp.net application and I have added a button. On click on the button, Creating a folder and subfolder in the SharePoint Documents library using the PnP core CSOM library.

The given below code create a folder and subfolder(inside the folder) in “Documents” Library.

AuthenticationManager authMgr = new AuthenticationManager();
string siteURL = "https://domainName.sharepoint.com/sites/TsInfoPNP";
string userName = "****@domainName.onmicrosoft.com";
string password = "*****";
protected void btnCreateFolder_Click(object sender, EventArgs e)
{
			createFolder();
}
public void createFolder()
{

	string listname = "Documents";
	string folderName = "Departments";
	try
	{
using (var ctx = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteURL, userName, password))
	{
	ctx.Load(ctx.Web);
	ctx.ExecuteQueryRetry();
	List list = ctx.Web.Lists.GetByTitle(listname);
	bool folderExists = list.RootFolder.FolderExists(folderName);
	if (!folderExists)
	{			 
Folder folder = list.RootFolder.CreateFolder(folderName).CreateFolder("IT");
	ctx.Load(folder);
	ctx.ExecuteQueryRetry();
	lblCreateFolder.Text = "Folder and SubFolder Created Successfully";
	}
	else
	{
	lblCreateFolder.Text = "Folder already exists";
	}
     }				
   }
catch (Exception ex) {

lblCreateFolder.Text = "Problem in creating folders in Documents library";	
			}
}

Run your application, click on Button “Create Folder in Documents Library”.

create folder in sharepoint document library
create folder in sharepoint document library

The below snapshot shows the folder “Departments” created in “Documents” library.

create folder in sharepoint list using pnp
create folder in sharepoint list using pnp

The below snapshot shows sub folder created inside the folder “Departments”.

sharepoint online create folder using pnp core csom
sharepoint online create folder using pnp core csom

Create Folder and Sub Folder inside SharePoint Master Page Gallery using PnP CSOM

We can create folders and subfolders inside the SharePoint master page gallery also. You just need to change the name of the list here like below:

string listname = "Master Page Gallery";

Check out:

In this SharePoint tutorial, we learned, how to create a folder and subfolder in SharePoint document library. Also, we have learned the below things:

  • Why use folders in SharePoint
  • SharePoint Create folder in List
  • Can we create folders in all SharePoint Lists
  • Create Folder in SharePoint Library
  • SharePoint folder or Metadata?
  • How many folders you can create in a SharePoint document library
  • SharePoint create folder in site pages
  • SharePoint create folder rest api
  • Create a folder inside SharePoint Online document library using browser
  • How to create a folder in document library in SharePoint Online using PnP CSOM
  • How to Create a folder in SharePoint document library using C#
  • How to Create a folder in SharePoint document library using Rest API
  • How to Create a folder in SharePoint document library using PowerShell
  • How to Create a folder in SharePoint document library using JavaScript
  • How to Create a folder in SharePoint document library using Flow
  • How to Create a folder in SharePoint document library using C# CSOM
  • >