简体   繁体   中英

Retrieve document template type from SPList

When working in SharePoint I am creating a custom SPList using the following method:

From 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. Is it possible to retrieve the document template type from an existing 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 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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