tags:

views:

64

answers:

2

Hello all,

I wonder how would I go about doing this.

I want to change a behavior for a list. When a list is added into sharepoint site, you can see 'Add New Item' underneath the list. When the user adds a new item, it should be replaced with 'Edit Item'

How can I achieve this?

Many thanks,

A: 

You can create a web part that will change the menu items available on the toolbar menu of the list.

In your web part code, change the code of the CreateChildControl :

    protected override void CreateChildControls()
    {
        if (!_error)
        {
            try
            {
                foreach (Control control in this.Page.Controls)
                {
                    ModifyMenu(control);
                }
                base.CreateChildControls();
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
    }

And then Add a ModifyMenu function that will add / hide the menus you want :

private void RemoveNewMenu(Control parentControl)
    {
        if ((parentControl == null) || (parentControl.Controls.Count == 0))
        {
            return;
        }

        foreach (Control childControl in parentControl.Controls)
        {
            if (childControl.ToString().ToUpper() == typeof(Microsoft.SharePoint.WebControls.NewMenu).ToString().ToUpper())
            {
                NewMenu newMenu = (NewMenu)childControl;

                if (newMenu.GetMenuItem("NewFolder") != null)
                {
                    newMenu.AddMenuItem(<Edit item menu that you want to add>);
                    newMenu.GetMenuItem(<new item menu that you want to Hide>).Visible = false;
                }

                break;
            }
            RemoveNewMenu(childControl);
        }
    }
Hugo Migneron
Many thanks for your excellent reply. My question is where will this web part be placed? On the same page as the list? If yes, then how to hide the webpart from the page and still achieve the functionality. Can you throw any pointers?
Carpentar
The web part will be placed on the same page as the list. If you set it's chrome type to "none" you won't see the web part at all as there are no controls in it. You will still see it when you go in page edit mode, but I imagine this won't be a problem as the people you are trying the hide the menus from probably don't have enough permissions to edit pages?
Hugo Migneron
A: 

Create a CustomAction and deploy it as a feature. The custom action should be a menu item that should be visible in the particular list and it's action url should be a link to the lists edit form edit form.

Hide other menu options using the following open source project that allows you to hide any menu item in the list's toolbar:

SharePoint features

Look for the Toolbar manager download.

Colin
Excellent, I was not even aware of this terminology before until you mentioned. I will study some more stuff on it and it seems that this is the right way of going about doing it. My question is if I do change the behavior what is the scope of that change - i mean to the current web or the whole web? Can you point some resourceful articles online with some step by step illustrated examples of this CustomAction stuff? Many thanks for your time and assistance.. I look forward for your reply..
Carpentar
Will try to look up some links, but googling for SharePoint+CustomAction will get you a long way. These can be web scoped features, and in the feature you would assign the customaction to a specific list (or content type within a list even). CustomActions can be used to edit the site actions menu as well, as well as the context menu's of list items.
Colin