Create document library programmatically in SharePoint

I have come across a scenario where I needed to create a document library programmatically inside SharePoint 2010 site collection, The “Document Library” is actually a list in SharePoint 2010 but just the template type is different.

Here is a method which I used to create a custom document library programatically.

protected void CreateNewDocumentLibrary()


SPSite site = SPContext.Current.Site;

SPWeb web = site.OpenWeb();

SPListTemplateType tempType = SPListTemplateType.DocumentLibrary;

web.Lists.Add("EbloginDocLibrary", null, tempType);


Once you run this code, go to “All site content” of your site collection you will see a new document library as you can see in below pic.

More Blogs

Contact us

To begin your digital transformation, get in touch.

We’re pleased to address any inquiries you might have and assist you in selecting the service that best suits your requirements.

Your benefits:
Speak To Us