代码添加内容类型,给列表添加内容类型

                        //遍历内容类型
                        SPContentTypeCollection collection = web.ContentTypes;
                        foreach (SPContentType item in collection)
                        {
                            list.ContentTypes.Add(item);
                            
                        }

                        //创建内容类型,并添加
                        //上传内容类型模板,1、在_cts目录下的<你的内容类型>文件夹下 ,通过contentType.DocumentTemplate得到默认内容类型路径
                        //2、自定义一个文档库,存放各种文件
                        string[] str = {"学校列表","教师任课情况表", "教职工惩处情况表", "教职工工作经历情况表", "教职工基本信息表", "教职工奖励情况表","教职工学习经历表", "教职工职称情况表", "校产数据表", 
                                           "校舍数据表", "学生惩戒处分情况表", "学生基本信息表", 
                                           "学生家庭成员信息表", "学生奖励情况表", "学生学习经历表"};
                        //SPContentType contentType = web.AvailableContentTypes[SPBuiltInContentTypeId.Item];
                        web.AllowUnsafeUpdates = true;
                        SPContentType parentCType = web.AvailableContentTypes[SPBuiltInContentTypeId.Document];
                        SPList list = web.Lists["基础数据收集库"];

                        list.ContentTypesEnabled = true;
                        for (int i = 0; i < str.Length; i++)
                        {
                            SPContentType childCType = new SPContentType(parentCType, web.ContentTypes, str[i]);
                            childCType.Group = "自定义内容类型";
                            // 将新的内容联系添加到网站内容类型集合
                            childCType = web.ContentTypes.Add(childCType);
                            childCType.DocumentTemplate = "新建 Microsoft Excel 工作表.xlsx";
                            childCType.Update();
                            // 添加到一个列表.
                            list.ContentTypes.Add(childCType);
                        }
                       
                        web.AllowUnsafeUpdates = false;

 

posted on 2015-06-08 13:49  !无名之辈  阅读(185)  评论(0)    收藏  举报