public static void CreateListStructure(SPWeb web) { var helper = new ListHelper(web) { Title = ListsName.DisplayName.MenuList, Name = ListsName.InternalName.MenuList, OnQuickLaunch = false, EnableAttachments = true }; helper.AddField(new MultipleLinesTextFieldCreator(FieldsName.MenuList.InternalName.Description, FieldsName.MenuList.DisplayName.Description) { RichText = false, RichTextMode = SPRichTextMode.Compatible }); helper.AddField(new SingleLineTextFieldCreator(FieldsName.MenuList.InternalName.MenuID, FieldsName.MenuList.DisplayName.MenuID)); helper.AddField(new NumberFieldCreator(FieldsName.MenuList.InternalName.MenuOrder, FieldsName.MenuList.DisplayName.MenuOrder)); helper.AddField(new NumberFieldCreator(FieldsName.MenuList.InternalName.MenuLevel, FieldsName.MenuList.DisplayName.MenuLevel) { DefaultValue = "1" }); helper.AddField(new SingleLineTextFieldCreator(FieldsName.MenuList.InternalName.ParentID, FieldsName.MenuList.DisplayName.ParentID)); helper.AddField(new SingleLineTextFieldCreator(FieldsName.MenuList.InternalName.ParentName, FieldsName.MenuList.DisplayName.ParentName)); helper.AddField(new SingleLineTextFieldCreator(FieldsName.MenuList.InternalName.CatID, FieldsName.MenuList.DisplayName.CatID)); helper.AddField(new SingleLineTextFieldCreator(FieldsName.MenuList.InternalName.CatName, FieldsName.MenuList.DisplayName.CatName)); helper.AddField(new SingleLineTextFieldCreator(FieldsName.MenuList.InternalName.PageName, FieldsName.MenuList.DisplayName.PageName)); helper.AddField(new SingleLineTextFieldCreator(FieldsName.MenuList.InternalName.MenuUrl, FieldsName.MenuList.DisplayName.MenuUrl)); var choiceField = new ChoiceFieldCreator(FieldsName.MenuList.InternalName.Status, FieldsName.MenuList.DisplayName.Status); choiceField.Choices.AddRange(new[] { "Ẩn", "Hiện" }); choiceField.DefaultValue = "Hiện"; helper.AddField(choiceField); choiceField = new ChoiceFieldCreator(FieldsName.MenuList.InternalName.MenuType, FieldsName.MenuList.DisplayName.MenuType); choiceField.Choices.AddRange(new[] { "Link tới chuyên mục", "Đường link xác định" }); choiceField.DefaultValue = "Link tới chuyên mục"; helper.AddField(choiceField); var choiceFields = new MultipleChoiceFieldCreator(FieldsName.MenuList.InternalName.MenuPosition, FieldsName.MenuList.DisplayName.MenuPosition); choiceFields.Choices.AddRange(new[] { "Top menu", "Footer menu", "Đơn vị" }); helper.AddField(choiceFields); choiceField = new ChoiceFieldCreator(FieldsName.MenuList.InternalName.OpenType, FieldsName.MenuList.DisplayName.OpenType); choiceField.Choices.AddRange(new[] { "Giữ nguyên cửa sổ hiện tại", "Mở cửa sổ mới" }); choiceField.DefaultValue = "Giữ nguyên cửa sổ hiện tại"; helper.AddField(choiceField); SPList list = helper.Apply(); SPField fieldTitle = list.Fields.GetFieldByInternalName(FieldsName.MenuList.InternalName.Title); if (fieldTitle != null) { fieldTitle.Title = FieldsName.MenuList.DisplayName.Title; fieldTitle.Update(); } list.Update(); //Add custom usercontrol to form Utilities.AddForms(web, list, "../../UserControls/MenuList.ascx"); //add view Utilities.AddStandardView(web, list, "AllMenu", "../../UserControls/MenuView.ascx", "", 100, true); }
public static void CreateListStructure(SPWeb web) { var helper = new ListHelper(web) { Title = ListsName.DisplayName.AdvList, Name = ListsName.InternalName.AdvList, OnQuickLaunch = false, EnableAttachments = false }; helper.AddField(new MultipleLinesTextFieldCreator(FieldsName.AdvList.InternalName.Description, FieldsName.AdvList.DisplayName.Description) { RichText = false, RichTextMode = SPRichTextMode.Compatible }); helper.AddField(new SingleLineTextFieldCreator(FieldsName.AdvList.InternalName.AdvID, FieldsName.AdvList.DisplayName.AdvID)); var choiceField = new ChoiceFieldCreator(FieldsName.AdvList.InternalName.AdvType, FieldsName.AdvList.DisplayName.AdvType); choiceField.Choices.AddRange(new[] { "Images", "Flash", "Video" }); choiceField.DefaultValue = "Images"; choiceField.Required = true; helper.AddField(choiceField); helper.AddField(new SingleLineTextFieldCreator(FieldsName.AdvList.InternalName.AdvFile, FieldsName.AdvList.DisplayName.AdvFile)); choiceField = new ChoiceFieldCreator(FieldsName.AdvList.InternalName.AdvOpenType, FieldsName.AdvList.DisplayName.AdvOpenType); choiceField.Choices.AddRange(new[] { "Giữ nguyên cửa sổ hiện tại", "Mở cửa sổ mới" }); choiceField.DefaultValue = "Mở cửa sổ mới"; choiceField.Required = true; helper.AddField(choiceField); helper.AddField(new NumberFieldCreator(FieldsName.AdvList.InternalName.AdvClick, FieldsName.AdvList.DisplayName.AdvClick)); helper.AddField(new SingleLineTextFieldCreator(FieldsName.AdvList.InternalName.AdvUrl, FieldsName.AdvList.DisplayName.AdvUrl) { Required = true }); helper.AddField(new NumberFieldCreator(FieldsName.AdvList.InternalName.AdvWidth, FieldsName.AdvList.DisplayName.AdvWidth) { Required = true }); helper.AddField(new NumberFieldCreator(FieldsName.AdvList.InternalName.AdvHeight, FieldsName.AdvList.DisplayName.AdvHeight) { Required = true }); helper.AddField(new NumberFieldCreator(FieldsName.AdvList.InternalName.AdvOrder, FieldsName.AdvList.DisplayName.AdvOrder) { Required = true, DefaultValue = "0" }); helper.AddField(new DateTimeFieldCreator(FieldsName.AdvList.InternalName.AdvStartDate, FieldsName.AdvList.DisplayName.AdvStartDate) { DisplayFormat = SPDateTimeFieldFormatType.DateTime, Required = true, DefaultValue = "[Today]" }); helper.AddField(new DateTimeFieldCreator(FieldsName.AdvList.InternalName.AdvEndDate, FieldsName.AdvList.DisplayName.AdvEndDate) { DisplayFormat = SPDateTimeFieldFormatType.DateTime, Required = true, DefaultValue = "[Today]" }); helper.AddField(new SingleLineTextFieldCreator(FieldsName.AdvList.InternalName.CustomerName, FieldsName.AdvList.DisplayName.CustomerName)); helper.AddField(new SingleLineTextFieldCreator(FieldsName.AdvList.InternalName.CustomerAddress, FieldsName.AdvList.DisplayName.CustomerAddress)); helper.AddField(new SingleLineTextFieldCreator(FieldsName.AdvList.InternalName.CustomerPhone, FieldsName.AdvList.DisplayName.CustomerPhone)); helper.AddField(new SingleLineTextFieldCreator(FieldsName.AdvList.InternalName.CustomerMobile, FieldsName.AdvList.DisplayName.CustomerMobile)); helper.AddField(new SingleLineTextFieldCreator(FieldsName.AdvList.InternalName.AdvCat, FieldsName.AdvList.DisplayName.AdvCat)); choiceField = new ChoiceFieldCreator(FieldsName.AdvList.InternalName.AdvDisplay, FieldsName.AdvList.DisplayName.AdvDisplay); choiceField.Choices.AddRange(new[] { "Hiển thị tất cả", "Hiển thị theo chuyên mục" }); choiceField.DefaultValue = "Hiển thị tất cả"; choiceField.Required = true; helper.AddField(choiceField); choiceField = new ChoiceFieldCreator(FieldsName.AdvList.InternalName.AdvPosition, FieldsName.AdvList.DisplayName.AdvPosition); choiceField.Choices.AddRange(new[] { "Trang chủ - bên trái - thứ nhất", "Trang chủ - bên trái - thứ 2", "Trang chủ - bên trái - thứ 3", "Trang chủ - bên trái - thứ 4", "Trang chủ - bên trái - thứ 5", "Trang chủ - bên trái - thứ 6", "Trang chủ - ở giữa", "Trang chủ - bên phải", "Trang tin - bên phải", "Trang tin chi tiết - bên phải", "Trang sơ đồ tổ chức - bên phải", "Trang thư viện file - bên phải", "Trang thư viện chi tiết - bên phải", "Trang giới thiệu - bên phải", "Trang văn bản - bên phải", "Trang thống kê - bên phải" }); choiceField.DefaultValue = "Trang chủ - bên trái - thứ nhất"; choiceField.Required = true; helper.AddField(choiceField); choiceField = new ChoiceFieldCreator(FieldsName.AdvList.InternalName.AdvStatus, FieldsName.AdvList.DisplayName.AdvStatus); choiceField.Choices.AddRange(new[] { "Ẩn", "Hiện" }); choiceField.DefaultValue = "Hiện"; choiceField.Required = true; helper.AddField(choiceField); SPList list = helper.Apply(); SPField fieldTitle = list.Fields.GetField(FieldsName.AdvList.InternalName.Title); if (fieldTitle != null) { fieldTitle.Title = FieldsName.AdvList.DisplayName.Title; fieldTitle.Update(); } list.Update(); //Add custom usercontrol to form Utilities.AddForms(web, list, "../../UserControls/AdvList.ascx"); var defaultView = list.DefaultView; defaultView.ViewFields.DeleteAll(); defaultView.RowLimit = 100; defaultView.Query = "<GroupBy Collapse='TRUE' GroupLimit='50'><FieldRef Name='" + FieldsName.AdvList.InternalName.AdvPosition + "' /></GroupBy>"; defaultView.ViewFields.Add(Constants.EditColumn); defaultView.ViewFields.Add(Constants.FieldTitleLinkToItem); defaultView.ViewFields.Add(FieldsName.AdvList.InternalName.CustomerName); defaultView.ViewFields.Add(FieldsName.AdvList.InternalName.AdvUrl); defaultView.ViewFields.Add(FieldsName.AdvList.InternalName.AdvStartDate); defaultView.ViewFields.Add(FieldsName.AdvList.InternalName.AdvEndDate); defaultView.Update(); }