fbpx

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.

     

5 Comments

Comments are closed.

About Us

Follow Us

Email: contact@keapoint.com
Phone:  0208 7852 888

Registered Address: 1 Amber Close, Reading, RG6 7ED. United Kingdom

Company No. 11586817