2

リストテンプレートを使用して新しいドキュメントライブラリを作成することは可能ですが、次のコードを試していますが、テンプレートを使用せずにライブラリを作成するだけです。sharepoint 2013リストテンプレートを使用してドキュメントライブラリを作成するC#

ListTemplateCollection listTemplates1 = context.Site.GetCustomListTemplates(context.Web); 
ListTemplate li1;// 
context.Load(listTemplates1); 
context.ExecuteQuery(); 
context.Load(site.ListTemplates); 
context.ExecuteQuery(); 

var listTemplate = listTemplates1.First(lt => lt.Name == "<Test>"); 

ListCreationInformation li = new ListCreationInformation(); 
li.Title = "XYZZ2"; 
li.Description = "Created through Code"; 
li.TemplateFeatureId = listTemplate.FeatureId; 
li.TemplateType = listTemplate.ListTemplateTypeKind; 
List newList = context.Web.Lists.Add(li); 
context.Load(newList); 
context.ExecuteQuery(); 

答えて

1

あなたは直接、代わりに次のようにコレクション全体を取得するテンプレートを取得しようとすることができます:

ListTemplate listTemplate = context.web.ListTemplates.GetByName("templateName"); 
context.Load(listTemplate); 
context.ExecuteQuery(); 

その後、あなたのリストを作成し、

ListCreationInformation li = new ListCreationInformation(); 
li.Title = "XYZZ2"; 
li.Description = "Created through Code"; 
li.TemplateFeatureId = listTemplate.FeatureId; 
li.TemplateType = listTemplate.ListTemplateTypeKind; 
List newList = context.Web.Lists.Add(li); 
context.Load(newList); 
context.ExecuteQuery(); 

これはlistTemplateかもしれあなたのケースでは、Listがデフォルトのテンプレートで作成されている理由が正しく初期化されていません。

+0

ありがとうございます。私はあなたのコードをテンプレートを取得しようとしましたが、私はデフォルトのテンプレートを持って、私はそれを使用したいカスタムテンプレート(フォルダ構造を持つドキュメントライブラリを含む)を作成しました。カスタムテンプレートを取得する方法。 –

関連する問題