Tuesday, March 1, 2011

Remove the SharePoint menu item “Edit in SharePoint Designer” in Site Action

I had a customer who wanted to remove the menu option "Edit in SharePoint Designer" in the site action. It was not simply enough to disable edit in SharePoint Designer in central administration, for it does not remove the the menu item but make it just gray.
My first thought was to make a Hidde custom action, but it turns out that many of the items in the site action can not remove by a Hidde custom action. It turns out that the menu items in the site action is hardcore in the master pagen. eg. v4.master. So we have four solutions to the problem position.
1) We can remove the rights of the logged on user.
2) In v4.master file, remove the line 147 to 157th
3) Do some JavaScript that remove the menu item
4) Make a custom control or delegate control ala:

  1. SPRibbon ribbonControl = this.Parent.Controls.Cast<Control>().First(c => (c is SPRibbon)) as SPRibbon;
  2. SPRibbonPeripheralContent ribbonPeripheralContent = ribbonControl.Controls[0] as SPRibbonPeripheralContent;
  3. SiteActions siteActions = ribbonPeripheralContent.Controls.Cast<Control>().First(c => (c is SiteActions)) as SiteActions;
  4. FeatureMenuTemplate featureMenuTemplate = siteActions.Controls[0].Controls[2] as FeatureMenuTemplate;
  5. Control editInSharePointDesigner = featureMenuTemplate.Controls.Cast<Control>().First(csd => (csd is MenuItemTemplate) && ((MenuItemTemplate)csd).Text.Equals("Edit in SharePoint Designer", StringComparison.InvariantCultureIgnoreCase));
  6. featureMenuTemplate.Controls.Remove(editInSharePointDesigner);

No comments:

Post a Comment