in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

tanujashares

Customize the OOB list menus in SharePoint 2007 lists

Customization in SharePoint List Menus-

In SharePoint 2007, as all of us know, portal can be created within very less span of time using the OOB features... but what if the customer is skeptical about certain UI and functionality which cannot be addressed by MOSS OOB features?

The only way is to go into SharePoint customizations and it takes a lot of effort to tweak few small things.

In the subsequent blog posts I am going to write about the different customizations that we can do in SharePoint 2007 & InfoPath 2007.

So start with menubar .... what do we get as OOB?

Its a toolbar defined as a user control ascx. This control takes care of the permissions assigned to user and appropriately allows the menus which are accessible to user.

Now, we want to add some other links, menus to the toolbar for our requirement, how should we customize it?

OK - This can be done using FEATURES in SharePoint 2007.

Step 1 - Create a list definition for the particular list.

Step 2 - Create a feature in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES withe the name you want, say "CustomMenu"

Step 3 - Then add Feature.xml file to this folder containing -

<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="{255E99BB-534A-4b93-AE6A-1691C300DF7C}"
    Title="Custom Menu"
    Description="This example shows how you can implement custom menu."
    Version="1.0.0.0"
    Scope="Site"
    xmlns="http://schemas.microsoft.com/sharepoint/">
 <ElementManifests>
  <ElementManifest Location="Element.xml" />
 </ElementManifests>
</Feature>

Step 4- Now add Element.xml file in the same folder containing -

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<CustomAction Id="CustomMenu"
   RegistrationType="List"
   RegistrationId="3001" 
   GroupId="NewMenu"
   Location="Microsoft.SharePoint.StandardMenu"
   Sequence="1000"
   ImageUrl="/_layouts/images/itann.gif"
   Title="Custom Menu for sample">
  <UrlAction Url=http://www.google.com/></UrlAction>
 </CustomAction>

</Elements>

In this config, you need to pass Registration Id as the list template ID you created in step 1 or the ID as 100, 101 for OOB custom list, document library etc.

Step 5- Install & deploy this feature using stsadm commands.

stsadm -o deactivatefeature -filename CustomMenu\Feature.xml -url http://localhost/
stsadm -o uninstallfeature -force -filename CustomMenu\Feature.xml
stsadm -o installfeature  -filename CustomMenu\Feature.xml
stsadm -o activatefeature -filename CustomMenu\Feature.xml -url http://localhost/

You need to put the URL of your site collection instead of putting http://localhost/

And here you go with the new menu in your list.

But what if you want to remove the existing menu as "New Item" as well? Is there any direct way similar to feature we used, to remove menu? The answer unfortnately is NO. And we need to try out some different technique now.

The technique is to modify the toolbar user control in Lists.

How to go for it?

Step 1 - Create new NewToolbar.ascx file

<%@ Control Language="C#"   AutoEventWireup="false" %>
<mailto:%25@Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<mailto:%25@Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.WebControls"%>
<mailto:%25@Register TagPrefix="Mymenu" Assembly="NewSubMenu, Version=1.0.0.0, Culture=neutral, PublicKeyToken=bb9e88afc6454ba1" namespace="Bechtel.eSub.NewSubMenu"%>
<mailto:%25@Register TagPrefix="SPHttpUtility" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.Utilities"%>
<%@ Register TagPrefix="wssuc" TagName="ToolBar" src="~/_controltemplates/ToolBar.ascx" mce_src="~/_controltemplates/ToolBar.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ToolBarButton" src="~/_controltemplates/ToolBarButton.ascx" mce_src="~/_controltemplates/ToolBarButton.ascx" %>

<SharePoint:RenderingTemplate ID="ViewToolBar1" runat="server">
 <Template>
  <wssuc:ToolBar CssClass="ms-menutoolbar" EnableViewState="false" id="toolBarTbl" ButtonSeparator="<img src='/_layouts/images/blank.gif' alt=''>" RightButtonSeparator="&nbsp;&nbsp;" runat="server">
   <Template_Buttons>
      
    <Mymenu:NewMenu ID="MyNewMenu" AccessKey="<%$Resources:wss,tb_NewMenu_AK%>" runat="server"/>
    <SharePoint:ActionsMenu  AccessKey="<%$Resources:wss,tb_ActionsMenu_AK%>" runat="server" />
    <SharePoint:SettingsMenu  AccessKey="<%$Resources:wss,tb_SettingsMenu_AK%>" runat="server" />
    </Template_Buttons>
   
   <Template_RightButtons>
      <SharePoint:PagingButton ID="PagingButton1" runat="server"/>
      <SharePoint:ListViewSelector ID="ListViewSelector1" runat="server"/>
   </Template_RightButtons>
  </wssuc:ToolBar>
 </Template>
</SharePoint:RenderingTemplate>

Step 2 - Save this file in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES

Step 3- Create a receiving class to add menus to this toolbar. So create a new class library project in Visual Studio 2005. Name it as per specified in ascx (NewSubMenu).

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.UI;

namespace NewSubMenu
{
    public class NewMenu : NewMenu
    {
        protected override void AddMenuItems()
        {
            AddMenuItem("1", "New Item", "", "Click here to copy an item to this list", "/_layouts/custompage.aspx", "");
            AddMenuItem("2", "New Itme 2", "", "Click here for next item ", "/_layouts/custompage.aspx", "");

        }

    }

}

Step 4- Compile this assembly and put it in GAC.

Step 5- Change the list defnition of the list in which you want to customize your menus. Go to schema.xml file and modify the following line to incorporate new toolbar in list-

<View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,All_Tasks;" DefaultView="TRUE" MobileView="True" MobileDefaultView="False" ToolbarTemplate="ViewToolBar1" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/issues.png" Url="AllItems.aspx>

Step 6- Redeploy the list definition using stsadm commands and iisreset and then here you go.

How can you change these menus for different list inherited from same list definition? -

Modify the class NewMenu we wrote to read the info from config list and populate menus depending upon the list name. So it will create the menus dynamically depending upon the list name.

In this class , this.lsit provides the SPList object of current list and you can play with it the way you want, before adding actual sub menus.

--tanuja

Comments

 

Links (1/13/2008) « Steve Pietrek’s SharePoint Stuff said:

Pingback from  Links (1/13/2008) &laquo; Steve Pietrek&#8217;s SharePoint Stuff

January 13, 2008 6:49 PM
 

Sandeep said:

Do u have any idea how to use the SPToolbar with Custom Webpart ? Suppose I have a webpart with SPGrid and displaying some TASKS list data.. but now the problem is that I am not able to get a Toolbar ? Do u know any way out ?

January 18, 2008 2:03 PM
 

Kannan said:

Hi,

Nice article.

We have a lot of Task lists in the Intranet. The users want to change the "New Item" to "New Task" in the top menu bar dropdown. Is there any way to achieve it through code?

Your help will be much appreciated.

Regards,

kannan

January 23, 2008 2:31 AM
 

tanujabapat said:

Hi Kannan,

You can very well customize your Task List as per the third option written in my blog to remove existing "New Item" link and add whatever menu you want.

Tanuja

January 23, 2008 5:55 PM
 

Cilaos [France] said:

Hi!

Your article is excellent but can you help me?

Can you describe how to create a list definition for the particular list (step 1) please?

Thanks very much for your help.

January 25, 2008 5:49 AM
 

Rupali Kothawade said:

Hi,

Excellent article.

You can use Visual studio template for List definition to create a List Definition. This is the easiest way to implement it.

Visual studio tool for creating the List template can be downloaded from below link.

www.microsoft.com/.../details.aspx

January 29, 2008 2:47 AM
 

moz said:

Please, explain step 5 at last example. Where is schema.xml  situated?

February 12, 2008 2:24 AM
 

deepak said:

hi,

great article. could you please help me how to remove action menu from the toolbar. customer dont want action menu to be there in the menu bar.

thanks in adv..

February 14, 2008 12:53 AM
 

tanuja said:

Deepak,

As per the 3rd option create a new ascx control toolbar.

While creating this ASCX in step 1, there are code lines like -

<Template_Buttons>

   <Mymenu:NewMenu ID="MyNewMenu" AccessKey="<%$Resources:wss,tb_NewMenu_AK%>" runat="server"/>

   <SharePoint:ActionsMenu  AccessKey="<%$Resources:wss,tb_ActionsMenu_AK%>" runat="server" />

   <SharePoint:SettingsMenu  AccessKey="<%$Resources:wss,tb_SettingsMenu_AK%>" runat="server" />

   </Template_Buttons>

Remove the Action menu related second tag to remove "Actions" menu from your list.

February 14, 2008 4:06 AM
 

Taneli said:

Hi,

Great article. Thanx. I can now remove existing menu items and add new ones, but I would like to add sub menu items to toolbar. Same way as in item level Send To -functionality is presented.

For example

New

    Group1

                 Item1

                 Item2

     Group2

                 Item3          

     Group3

NewMenu.AddMenuItem method does not allow me to do that. Do you know how to do that?

March 7, 2008 5:57 AM
 

Atul said:

Thanks for Sharing !

March 13, 2008 4:01 PM
 

DRegos said:

Hi!

I've done the first part step by step. And as I've understood, the custom menu item as shown on the picture, should already be on my Custom List. True?

Well I'm not seing it? Help.

March 19, 2008 10:51 AM
 

Hi! Me Again said:

I've created:

- my custom list definition.

- feature CustomMenu

In custom menu Feature.xml I've assigned RegistrationID as my custom list guid.

Anyway when I get this error...

Exception from HRESULT: 0x81070201   at Microsoft.SharePoint.Library.SPRequestInternalClass.CreateListFromFormPost(String bstrUrl, String& pbstrGuid, String& pbstrNextUrl)

  at Microsoft.SharePoint.Library.SPRequest.CreateListFromFormPost(String bstrUrl, String& pbstrGuid, String& pbstrNextUrl)

March 20, 2008 9:42 AM
 

Sorry said:

Element.xml instead of Feature.xml

March 20, 2008 9:44 AM
 

PrashanthSpark said:

How do i deploy feature if i dont have admin rights to run stsadm command...

Can i use C# code to register..

March 26, 2008 11:56 PM
 

Marcin said:

Hello

My question is: How to change an icon next to new item?

For example if a list can contain folders, there is a yellow folder next to new folder item.

Best ragrds

write me back

marcinmigdal@wp.pl

Marcin

June 23, 2008 7:03 AM
 

PJ said:

Hi,

Thanks for the post.

I tried to work but I am not able to get through.

I am trying to do as below.

I have 4 menu items under NEW. So when user clicks on NEW menu, the user will get to see 4 sub-menu items. These 4 menu items represent CONTENT TYPES.

Now question is these 4 menu items should not be shown to all users but instead I need to apply security here. That is if UserA logs in I know that this user needs Submenu2 and Submenu4 and I will need to disable or hide Submenu3 or Submenu4.

Please suggest me how can I acehive this.

Alternatively is there a way to completely hide NEW altogther. I thought of this so that I can completely hide "NEW" and then create a new menu called "Entry forms" and then check for security permissions of USER and start creating Submenu items. Is this feasible in sharepoint (wss)?

Please suggest.

MrChiltu@rediffmail.com

July 9, 2008 6:49 PM
 

Fernando (Portugal) said:

Hello,

I need help with my sharepoint project...How can I customize the help menu of sharepoint?....How can I customize the errors pages and the login and logout pages of my sharepoint???....

If any person knows how to do or know any place in the web that could help me please send me a mail to fersango@gmail.com.

Thanks

July 31, 2008 12:41 PM
 

Fernando (Portugal) said:

Hello,

I need help with my sharepoint project...How can I customize the help menu of sharepoint?....How can I customize the errors pages and the login and logout pages of my sharepoint???....

If any person knows how to do or know any place in the web that could help me please send me a mail to fersango@gmail.com.

Thanks

July 31, 2008 12:42 PM
 

Murali said:

Can i get the complete same of these?

Murali

October 21, 2008 2:07 AM
 

Sonal said:

Where is the schema.xml file for a particular list is located?

October 27, 2008 6:17 AM

Leave a Comment

(required )  
(optional )
(required )  
Add

Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts