【问题标题】:Retrieve document template type from SPList从 SPList 中检索文档模板类型
【发布时间】:2017-05-05 00:49:55
【问题描述】:

在 SharePoint 中工作时,我正在使用以下方法创建自定义 SPList:

来自MSDN:

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

传递 docTemplateType 来声明文档模板类型。是否可以从现有的 SPList 中检索文档模板类型?这可能很有用,即在复制列表时。

提前致谢。

【问题讨论】:

    标签: c# sharepoint


    【解决方案1】:

    使用SPList.BaseTemplate property获取列表所基于的列表定义类型,例如:

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

    如何获取与列表关联的文档模板

    SPList list = web.Lists.TryGetList(<list title>);
    
    var docTemplate = web.ListTemplates.OfType<SPListTemplate>()
                                       .FirstOrDefault(lt => lt.Type == list.BaseTemplate); 
    
    Console.WriteLine(docTemplate.DocumentTemplate);
    

    【讨论】:

    • 感谢您的回答。不幸的是,这将返回列表本身的模板(即文档库、讨论区等),而不是文档模板列表。
    • 答案已更新,见章节:如何获取与列表关联的文档模板
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-04
    • 1970-01-01
    • 1970-01-01
    • 2012-01-30
    • 2017-12-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多