public static void SetMenuVisibility(ActionsMenu menu, string menuItemId, bool visible) { try { menu.GetMenuItem(menuItemId).Visible = visible; } catch (Exception exception) { Trace.WriteLine(exception); } }
private void processControls(Control parentControl, string listname, string listid, string viewid, string defaultcontrol, string webpartid, string ZoneIndex, bool hideNew) { foreach (Control childControl in parentControl.Controls) { if (childControl.ToString() == "System.Web.UI.WebControls.Label") { if (childControl.ID == "lblFilter") { //System.Web.UI.WebControls.HyperLink hl = (System.Web.UI.WebControls.HyperLink)childControl; //hl.NavigateUrl = "Javascript:switchFilter" + ZoneIndex + "('" + hl.ClientID + "');"; try { System.Web.UI.WebControls.Label lblFilterText = (System.Web.UI.WebControls.Label)parentControl.FindControl("lblFilterText"); System.Web.UI.WebControls.Label lblLink = (System.Web.UI.WebControls.Label)childControl; lblLink.Text = "<a onclick=\"Javascript:switchFilter" + ZoneIndex + "('" + lblFilterText.ClientID + "');\">"; filterIndex = parentControl.Parent.Controls.IndexOf(parentControl); } catch { } } } if (childControl.ToString().ToUpper() == "MICROSOFT.SHAREPOINT.WEBCONTROLS.NEWMENU") { if (hideNew) { childControl.Visible = false; } else if (useNewMenu) { if (hasList) { NewMenu menu = (NewMenu)childControl; try { Microsoft.SharePoint.WebControls.MenuItemTemplate mnu = menu.GetMenuItem("New0"); mnu.ClientOnClickNavigateUrl = "javascript:newAppPopup('" + list.ID.ToString().ToUpper() + @"');"; string txt = mnu.Text; int spaceloc = txt.IndexOf(" "); txt = txt.Substring(0, spaceloc); if (newMenuName == "") { mnu.Text = txt + " " + listname; } else { mnu.Text = txt + " " + newMenuName; } menu.MenuControl.ClientOnClickScript = "javascript:newAppPopup('" + list.ID.ToString().ToUpper() + @"');"; } catch { } } else { NewMenu menu = (NewMenu)childControl; try { Microsoft.SharePoint.WebControls.MenuItemTemplate mnu = menu.GetMenuItem("New0"); mnu.ClientOnClickNavigateUrl = SPContext.Current.Web.Url + "/_layouts/epmlive/newapp.aspx?List=" + listid; string txt = mnu.Text; int spaceloc = txt.IndexOf(" "); txt = txt.Substring(0, spaceloc); if (newMenuName == "") { mnu.Text = txt + " " + listname; } else { mnu.Text = txt + " " + newMenuName; } menu.MenuControl.ClientOnClickScript = "location.href='" + mnu.ClientOnClickNavigateUrl + "'"; } catch { } } } else if (listname != "Project Center" && listname != "Project Center Rollup" && rollupLists != "" && !disableNewButtonModification) { NewMenu menu = (NewMenu)childControl; try { menu.GetMenuItem("New0").Visible = false; menu.MenuControl.NavigateUrl = ""; menu.MenuControl.ClientOnClickScript = ""; string[] arrrolluplists = rollupLists.Split(','); foreach (string rolluplist in arrrolluplists) { string[] arrrolluplist = rolluplist.Split('|'); string image = ""; try { image = "/_layouts/images/" + arrrolluplist[1]; } catch { } menu.AddMenuItem("New1", "New " + arrrolluplist[0].Trim() + " Item", "", "", SPContext.Current.Web.Url + "/_layouts/epmlive/newitem.aspx?List=" + arrrolluplist[0] + "&Source=" + HttpUtility.UrlEncode(HttpContext.Current.Request.Url.ToString()), ""); } } catch { } } else { NewMenu menu = (NewMenu)childControl; MenuItemTemplate template = menu.GetMenuItem("New0"); } } if (childControl.ToString().ToUpper() == "MICROSOFT.SHAREPOINT.WEBCONTROLS.ACTIONSMENU") { ActionsMenu menu = (ActionsMenu)childControl; if (rollupLists != "") { try { menu.GetMenuItem("EditInGridButton").Visible = false; } catch { } try { menu.GetMenuItem("ExportToDatabase").Visible = false; } catch { } if (rollupLists != "") { try { menu.GetMenuItem("ViewRSS").Visible = false; } catch { } try { menu.GetMenuItem("SubscribeButton").Visible = false; } catch { } } try { SPWeb web = SPContext.Current.Web; MenuItemTemplate mnu = menu.GetMenuItem("ExportToSpreadsheet"); mnu.ClientOnClickScript = "location.href='" + web.ServerRelativeUrl + "/_layouts/epmlive/rollupexport.aspx?List=" + listid + "&View=" + viewid + "&Lists=" + HttpUtility.UrlEncode(rollupLists.Replace(",", ";")) + "'"; } catch { } } string url = HttpContext.Current.Request.Url.AbsolutePath; if (url.Contains("?")) { url += "&"; } else { url += "?"; } if (defaultcontrol.ToLower() == "grid") { } else if (defaultcontrol.ToLower() == "gantt") { menu.AddMenuItem("ViewInGrid", "View In Grid", "/_layouts/epmlive/images/menugridview.GIF", "View list using EPM Live Grid.", url + "webpartid=" + webpartid + "&gridmode=grid", ""); } } if (childControl == null) { return; } processControls(childControl, listname, listid, viewid, defaultcontrol, webpartid, ZoneIndex, hideNew); } }