Sharepoint 在指定的网站中创建列表或文档库

   
        /// <summary>

        /// 在指定网站中创建列表或文档库

         /// </summary>

        /// <param name="strName">列表或文档库名称</param>

        /// <param name="strWebUrl">指定的url</param>

        /// <param name="strType">类型,如“列表,文档库,图片库”等</param>

        /// <param name="strDescription">描述</param>

        private void CreateModule(string strName, string strWebUrl, string strType, string strDescription)

        {

            SPSecurity.RunWithElevatedPrivileges(delegate() {

                try

                {

                    using (SPSite site = SPContext.Current.Site)

                    {

                        using (SPWeb web = site.OpenWeb(strWebUrl))

                        {

                            SPListCollection collList = web.Lists;

                            collList.Add(strName, strDescription, GetListTemplate(strType));

                        }

                    }

                }

                catch (Exception ex) { throw ex; }

            });

        }





  

        /// <summary>

        /// 得到列表类型

         /// </summary>

        /// <param name="strType"></param>

        /// <returns></returns>

        private SPListTemplateType GetListTemplate(string strType)

        {

            SPListTemplateType listTemplateType = new SPListTemplateType();



            switch (strType)

            {

                case "Announcements":

                    listTemplateType = SPListTemplateType.Announcements;

                    break;

                case "Custom List":

                    listTemplateType = SPListTemplateType.GenericList;

                    break;

                case "Document Library":

                    listTemplateType = SPListTemplateType.DocumentLibrary;

                    break;

                case "Picture Library":

                    listTemplateType = SPListTemplateType.PictureLibrary;

                    break;

                case "Wiki Page Library":

                    listTemplateType = SPListTemplateType.WebPageLibrary;

                    break;

                case "Survey":

                    listTemplateType = SPListTemplateType.Survey;

                    break;

                case "Contact":

                    listTemplateType = SPListTemplateType.Contacts;

                    break;

                case "Discussion Board":

                    listTemplateType = SPListTemplateType.DiscussionBoard;

                    break;

                case "Form Library":

                    listTemplateType = SPListTemplateType.XMLForm;

                    break;

            }



            return listTemplateType;

        }

你可能感兴趣的:(SharePoint)