Change List Settings
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,
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);
}
}
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.
精彩评论