【问题标题】:Creating a list based on a list definition template基于列表定义模板创建列表
【发布时间】:2023-03-19 23:53:01
【问题描述】:

我的解决方案中有一个列表定义,我希望能够以编程方式基于该列表定义创建一个列表,谁能告诉我该怎么做?

<ListTemplate
    Name="Mylise"
    Type="10778"
    BaseType="0"
    OnQuickLaunch="TRUE"
    SecurityBits="11"
    Sequence="410"
    DisplayName="My new List"
    Description="My own list"
    Image="/_layouts/images/itgen.png"/>

【问题讨论】:

  • 什么样的列表?在什么样的应用中,在什么时候?你试过什么?
  • 如果要生成类,可以使用tt文件。

标签: c# list sharepoint templates


【解决方案1】:

打电话

var customTemplate = yourSPWeb.ListTemplates["Mylise"];

获取列表模板对象,然后

yourSPWeb.Lists.Add("List title", "List description", customTemplate);

创建列表。

【讨论】:

    【解决方案2】:
    try
    {
      SPList list = null;
      using (SPSite site = new SPSite("http://yoursite/"))
      {
         using (SPWeb web = site.RootWeb)
         {
          //List Will be Created Based on this ListDefinition
    - OOB Custom List Definition
          //00BFEA71-DE22-43B2-A848-C05709900100
    
            foreach (SPList _list in web.Lists)
            {
              if (_list.Title.Equals("TestList"))
              {
                  list = _list;
              }
            }
    
            if (list == null)
            {
             web.AllowUnsafeUpdates = true;
             Guid listID = web.Lists.Add("TestList", //List Title
                          "This is Test List",      //List Description
                          "Lists/TestList",         //List Url
                          "00BFEA71-DE22-43B2-A848-C05709900100", //Feature Id of List definition Provisioning Feature – CustomList Feature Id
                           10778,                     //List Template Type
                         "101");      //Document Template Type .. 101 is for None
    
               web.Update();
               web.AllowUnsafeUpdates = false;
    
             }
            }
    
    
         }
        }
        catch (Exception ex)
        {
    
        }
    

    希望这对你有帮助:)

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-10
    • 2018-10-15
    • 2018-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-06
    相关资源
    最近更新 更多