8
votes

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

2

2 Answers

8
votes

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();
}
4
votes

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

lci.TemplateType = (int) ListTemplateType.DocumentLibrary;