private void PopulateControls(string Group)//, PageLayout pageLayout) { SPWeb rootWeb = SPContext.Current.Site.RootWeb; SPContentTypeCollection availableContentTypes = rootWeb.AvailableContentTypes; foreach (SPContentType contenttype in availableContentTypes) { if (contenttype.Group == Group)//"Publishing Content Types") { //if (contenttype.Id == SPContext.Current.ListItem.ContentTypeId) //{ List <PageLayout> layouts = servicePageLayouts.GetPageLayouts(contenttype.Id); foreach (PageLayout layout in layouts) { ListItem item = new ListItem(layout.Title, layout.UniqueId.ToString()); if (!this.ddl_PublishingLayout.Items.Contains(item)) { this.ddl_PublishingLayout.Items.Add(item); } } //} } } /* * if (this.ddl_PublishingLayout.Items.Count > 0) * { * if (SPContentTypeId.Empty != contentTypeId) * { * SPContentType current = availableContentTypes[contentTypeId]; * this.ddl_PublishingLayout.SelectedValue = current.Id.ToString(); * this.lbl_Description.Text = current.Description; * } * else * { * SPContentType current = availableContentTypes[new SPContentTypeId(this.ddl_PublishingLayout.Items[0].Value)]; * this.lbl_Description.Text = current.Description; * } */ /* * //this.ddl_contentname.SelectedValue = Hemrika.SharePresence.WebSite.ContentTypes.ContentTypeId.PageLayout.ToString(); * SPContentType type = availableContentTypes[new SPContentTypeId(this.ddl_PublishingLayout.Items[0].Value)]; * this.lbl_Description.Text = type.Description; */ //} }
protected void Page_Load(object sender, EventArgs e) { if (!base.IsPostBack) { SPWeb web = SPContext.Current.Web; SPWeb rootWeb = SPContext.Current.Site.RootWeb; foreach (SPList list in web.Lists) { if (list.BaseType == SPBaseType.DocumentLibrary) { SPDocumentLibrary docLib = (SPDocumentLibrary)list; if (docLib.IsCatalog == false && !list.IsApplicationList && !list.IsSiteAssetsLibrary && ContainsWebSitePageTypes(list)) { ListItem item = new ListItem(list.Title, list.ID.ToString()); if (!this.ddl_library.Items.Contains(item)) { this.ddl_library.Items.Add(item); } } } } //TODO ListId queryparam try { this.ddl_library.SelectedValue = Request.Params["list"].ToString(); } catch (Exception ex) { ex.ToString(); } SPContentTypeCollection availableContentTypes = rootWeb.AvailableContentTypes; foreach (SPContentType contenttype in availableContentTypes) { if (!this.ddl_contentgroup.Items.Contains(new ListItem(contenttype.Group))) { this.ddl_contentgroup.Items.Add(contenttype.Group); } } this.ddl_contentgroup.Items.Remove("_Hidden"); this.ddl_contentgroup.SelectedValue = "Publishing Content Types"; foreach (SPContentType contenttype in availableContentTypes) { if (contenttype.Group == this.ddl_contentgroup.SelectedValue) { List <PageLayout> check = servicePageLayouts.GetPageLayouts(contenttype.Id); if (check.Count > 0) { ListItem item = new ListItem(contenttype.Name, contenttype.Id.ToString()); this.ddl_contentname.Items.Add(item); } } } if (this.ddl_contentname.Items.Count > 0) { this.ddl_contentname.SelectedIndex = 0;; SPContentTypeId contenttypeid = new SPContentTypeId(this.ddl_contentname.SelectedValue); List <PageLayout> layouts = servicePageLayouts.GetPageLayouts(contenttypeid); //layouts.AddRange(servicePageLayouts.GetPageLayouts(contenttypeid.Parent)); foreach (PageLayout layout in layouts) { ListItem item = new ListItem(layout.Title, layout.UniqueId.ToString()); if (!this.ddl_pagelayout.Items.Contains(item)) { this.ddl_pagelayout.Items.Add(item); } } if (this.ddl_pagelayout.Items.Count > 0) { PageLayout layout = servicePageLayouts.GetPageLayout(new Guid(this.ddl_pagelayout.Items[0].Value)); this.lbl_description.Text = layout.Description; } } } }
//public override TabDefinition GetTabDefinition() public TabDefinition GetTabDefinition() { var groups = new List <GroupDefinition>(); var listsettings = new List <ControlDefinition>(); var listbutton = new ButtonDefinition() { Id = "PageLayoutList", Title = "PageLayouts", Image = ImageLibrary.GetStandardImage(13, 1), CommandJavaScript = "ShowPagelayoutList();", TemplateAlias = "c1" }; listsettings.Add(listbutton); var settings = new GroupDefinition() { Id = "PageLayouts", Title = "Pagelayouts for this site", Sequence = "10", Template = GroupTemplateLibrary.SimpleTemplate, Controls = listsettings.ToArray() }; groups.Add(settings); //int index = 0; //int sequence = 30; SPContentTypeId contentTypeId = (SPContentTypeId)SPContext.Current.ListItem[SPBuiltInFieldId.ContentTypeId]; string contentType = SPContext.Current.ListItem[SPBuiltInFieldId.ContentType].ToString(); //string id = SPContext.Current.ListItem[SPBuiltInFieldId.ContentTypeId].ToString(); //SPContentTypeId contentTypeId = new SPContentTypeId(id); //foreach (string category in Categories) //{ List <PageLayout> layouts = servicePageLayouts.GetPageLayouts().Where(n => n.ContenTypeId == contentTypeId).Select(n => n).ToList(); layouts.AddRange(servicePageLayouts.GetPageLayouts().Where(n => n.ContenTypeId == contentTypeId.Parent).Select(n => n).ToList()); layouts.AddRange(servicePageLayouts.GetPageLayouts().Where(n => n.ContenTypeId.Parent == contentTypeId).Select(n => n).ToList()); if (layouts.Count > 0) { var controls = new List <ControlDefinition>(); foreach (PageLayout item in layouts) { ImageDefinition image = new ImageDefinition(); image.Url16 = item.Icon; image.Url32 = item.Icon; ToolTipDefinition tooltip = new ToolTipDefinition(); tooltip.Description = item.Description.ToString(); tooltip.Title = item.Title; tooltip.Image = item.Preview; tooltip.Class = "tooltip_preview"; url = base.parentStateControl.ContextUri; if (IsEditMode(this.Page)) { url = WebPageStateControl.AddQueryStringParameter(WebPageStateControl.AddQueryStringParameter(url, "ControlMode", "Edit"), "DisplayMode", "Design"); } url = WebPageStateControl.AddQueryStringParameter(url, "PageLayout", DateTime.Now.Ticks.ToString()); var button = new ButtonDefinition() { Id = item.Title.Replace(" ", String.Empty).Trim(), Title = item.Title, ToolTip = tooltip, Image = image, CommandEnableJavaScript = "document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value == 0", CommandJavaScript = String.Format("ChangePageLayout('{0}','{1}','{2}')", this.ClientID, url, item.UniqueId), TemplateAlias = "c1" }; controls.Add(button); } var group = new GroupDefinition() { Id = "PageLayouts", Title = "Pagelayouts for ContentType " + contentType, Sequence = "10", Template = GroupTemplateLibrary.SimpleTemplate, Controls = controls.ToArray() }; groups.Add(group); //sequence += 10; //index += 1; } //} if (groups.Count > 0) { return(new TabDefinition() { Id = "Hemrika.SharePresence.Design", Title = "Design", Sequence = "120", GroupTemplates = GroupTemplateLibrary.AllTemplates, Groups = groups.ToArray() }); } else { return(null); } }