【Sharepoint对象模型】MOSS中根据列表模板添加列表

其实只是用到了添加时的一个方法,类似的,可以根据模板添加网站等。
用于新建项目时单个项目构建网站。
 
 1                  //添加列表
 2                             //Guid newListId = web.Lists.Add("任务列表", "", SPListTemplateType.Announcements);
 3                             ////设置列表显示在快速启动栏
 4                             //SPList newList = web.Lists[newListId];
 5                             //newList.OnQuickLaunch = true;
 6                             //newList.Update();
 7                             //web.Dispose();
 8  
 9                             string TemplateName = "thistask.stp" ;//需要根据所建模版名称进行修改
10                             SPListTemplate CustomTemplate = null ;
11                             SPListTemplateCollection ListTemplateCollection = web.Site.GetCustomListTemplates(web);
12                             foreach (SPListTemplate template in ListTemplateCollection)
13                             {
14                                 if (template.InternalName == TemplateName)
15                                 {
16                                     CustomTemplate = template;
17                                     break;
18                                 }
19                             }
20                             web.AllowUnsafeUpdates = true;
21                             string ListName = ProjectName.Text;
22                             Guid guidDiscussionBoard = web.Lists.Add(ListName, "", CustomTemplate);
23                             SPList newList = web.Lists[guidDiscussionBoard];
24                             newList.OnQuickLaunch = true;
25                             newList.Update();
26                             web.Dispose();
原文地址:https://www.cnblogs.com/yixiaozi/p/3844098.html