简体   繁体   English

从SPList检索文档模板类型

[英]Retrieve document template type from SPList

When working in SharePoint I am creating a custom SPList using the following method: 在SharePoint中工作时,我正在使用以下方法创建自定义SPList:

From MSDN : MSDN

public virtual Guid Add(
    string title,
    string description,
    string url,
    string featureId,
    int templateType,
    string docTemplateType,
    SPListTemplate.QuickLaunchOptions quickLaunchOptions
)

The docTemplateType is passed to declare the document template type. 传递docTemplateType来声明文档模板类型。 Is it possible to retrieve the document template type from an existing SPList? 是否可以从现有的SPList中检索文档模板类型? This can be useful ie when copying a list. 这可能很有用,即在复制列表时。

Thanks in advance. 提前致谢。

Use SPList.BaseTemplate property to get the list definition type on which the list is based, for example: 使用SPList.BaseTemplate属性可获取列表所基于的列表定义类型,例如:

SPList list = web.Lists.TryGetList(<list title>);
SPListTemplateType templateType = list.BaseTemplate;
int templateTypeId = (int) templateType;

How to get Document Template associated with List 如何获取与列表关联的文档模板

SPList list = web.Lists.TryGetList(<list title>);

var docTemplate = web.ListTemplates.OfType<SPListTemplate>()
                                   .FirstOrDefault(lt => lt.Type == list.BaseTemplate); 

Console.WriteLine(docTemplate.DocumentTemplate);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM