Hi guys,

This time i will share with you another methods to over come boring SharePoint works. Create a folder in document library is easy but how about hundreds of folders. This is the way i use to create multiple folder in a library. All you need is trial visual studio and client object model dll file. Then create console application and use following codes.

I hope it helps.. it surely helped me 🙂



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Client;

namespace create_folder
{
class Program
{
static void Main(string[] args)
{
ClientContext clientContext = new ClientContext("https://Sharepointsiteurl");
Web rootWeb = clientContext.Web;

//Get List
var query = clientContext.LoadQuery(rootWeb.Lists.Where(p => p.Title == "SharedFolder"));
clientContext.ExecuteQuery();
List list = query.FirstOrDefault();

string[] namesArray = new string[] {  "Folder1","Folder2"};
foreach (string name in namesArray)
{
//Add Folder
var folders = list.RootFolder.Folders;
clientContext.Load(folders);
clientContext.ExecuteQuery();
var newFolder = folders.Add(name);
Console.WriteLine(name);
}
//Execute request
clientContext.ExecuteQuery();
}

}
}