سؤال

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

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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

lci.TemplateType = (int) ListTemplateType.DocumentLibrary;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top