Thursday, November 4, 2010

Hiding “New Site” in Site Actions Menu

Today, I came across an interesting question in a forum and the question was.. “How to hide “New Site” option available in the Site Actions menu when the publishing feature is enabled.

Initially, I thought it would be easy with HideCustomAction element in a custom feature. However, it did not turn out to be that easy. After some investigation I figured out that that menu item is created by Publishing feature in code. HideCustomAction would have helped me if it was created declaratively. So, I took the same approach as Publishing feature to hide the menu. Here is the solution:

This was tough when I started doing it today. It is possible via feature using a CustomAction element in the elements.xml and some code. I tried a no-code solution but it was not possible.

 <CustomAction
        Id="HideCreateSiteInSiteActions"
        Location="Microsoft.SharePoint.StandardMenu"
        GroupId="SiteActions"
        Sequence="901"
        Title="Publishing SiteActions Menu Customization"
        ControlAssembly="Your Assembly full name"        ControlClass="your class full name">
  </CustomAction>

Following code would go in class:

public class YourClassName : WebControl
    {
        protected override void OnLoad(EventArgs e)
        {
            var siteActions = ToolBarMenuButton.GetMenuControl(this);
            siteActions.MenuControl.PreRender += (o, args) =>
            {
                var targetMenu = siteActions.GetMenuItem("MenuItem_CreateSite");
                if (targetMenu == null) return;
                siteActions.MenuControl.HiddenMenuItems.Add(targetMenu);
            };
        }       
    }

The scope of your feature would be "site". Also, don't forget to put SafeControl entry for your class in the web.config or it may not work.

Monday, November 1, 2010

I am active at StackOverflow.com and SharePointOverflow.com

Recently I came across a presentation from Scott Hanselman and he insisted that “Every Developer must have a blog.. period..”. After inspired by that presentation, I thought of giving it a try and I decided to spend a few hours every week for these two activities:

1. Help the community by answering the questions they have!

2. Blog interesting things that I come across

For the first activity, I decided to actively participate in SharePoint 2007/2010 related questions posted by people at StackOverflow.com and SharePointOverflow.com. I like these sites because they are simple and fast.. very simple reason indeed! And here I am, after one month of this activity, I gave about 50 answers and collected about 700 points. Wow, looking back, I did not anticipate that I would give that many answers and get many points! I must state that I enjoyed a lot while helping the community, I learnt a lot. Many of those answers that I have required me to research and even work with VS.NET to get the correct answer. So, I want to continue with this… and who knows after a year I may be recognized by Microsoft as an MVP… that would a quite an achievement.. pinch me, I am dreaming!

This blog and the posts that created last month is the proof of my second activity. Let’s see how many interesting things I come across and I am able to blog it or not!

Wrong values for Location and GroupID of Custom Actions specified in SharePoint SDK

While I was researching a problem reported by a user @ SharePointoverflow.com, I realized that if I wanted to add a link to Central Admin site’s “Site Collection” section of “Application Management” and use the Location and GroupID specified in SharePoint SDK, it would NOT work!

It wasn’t a pleasant surprise to me. The problem which lead me to investigate the issue is: http://www.sharepointoverflow.com/questions/6689/central-admin-custom-action-menu-not-appearing

If you are interested in correct values, please visit: http://bloggingabout.net/blogs/arjen/archive/2010/02/04/custom-action-definitions-in-sharepoint-2010.aspx

I finally found the problem and answered to the user. It turned out that I have to mark the feature element with AutoActivateInCentralAdmin="TRUE" so that when the feature which is scoped at “Web” would activate automatically in the central administration and display my custom action.