Create document library programmatically in SharePoint
15 March 2011

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.





































