Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Document Library using Client Object Model

Just a quick question, is it possible to create a Document Library using the Client Object Model in SharePoint 2010?

I know you can create lists etc. Am I right in saying that a Document Library is just a 'special' type of List?

How can I specify that the List I create will be a Document Library?

Any help will be appreciated

Thanks

like image 594
Josh Price Avatar asked Apr 18 '13 09:04

Josh Price


2 Answers

Yes. You can specify the TemplateType for your List.

List of TemplateTypes

using (ClientContext clientCTX = new ClientContext(url))
{
     ListCreationInformation lci = new ListCreationInformation();
     lci.Description = "My own DocLib";
     lci.Title = "Library";
     lci.TemplateType = 101;
     List newLib = clientCTX.Web.Lists.Add(lci);
     clientCTX.Load(newLib);
     clientCTX.ExecuteQuery();
}
like image 68
David Schenk Avatar answered Sep 30 '22 11:09

David Schenk


You can also set the templatetype with the following code, which I think makes things clearer to new programmers:

lci.TemplateType = (int) ListTemplateType.DocumentLibrary;
like image 30
richard pyra Avatar answered Sep 30 '22 12:09

richard pyra