victorzki
victorzki

Reputation: 45

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 i.e. when copying a list.

Thanks in advance.

Upvotes: 0

Views: 1231

Answers (1)

Vadim Gremyachev
Vadim Gremyachev

Reputation: 59378

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

Upvotes: 2

Related Questions