Tag Archive for ECB

Add ECB to View Columns

Some code to add the ECB menu to the specified columns of a view:

public void SetEcbColumnOnView(SPView view, List<string> internalNames)
    if (view == null)
        throw new ArgumentNullException("view");
    const string ListItemMenu = "ListItemMenu";
    const string ViewFields = "ViewFields";
    const string AttributeName = "Name";
    XElement root = XElement.Parse(view.GetViewXml());
    // Get all columns that use the ECB menu
    IEnumerable<XElement> fields = from el in root.Elements(ViewFields).DescendantNodes().OfType<XElement>()
                                    where el.Attribute(ListItemMenu) != null
                                    select el;
    // Remove the ECB Menu from all columns that currently use it.
    foreach (XElement el in fields)
    if (internalNames.Count > 0)
        //Get the field specified in the parameters
        fields = from el in root.Elements(ViewFields).DescendantNodes().OfType<XElement>()
                    let nameAttribute = el.Attribute(AttributeName)
                    where nameAttribute != null && internalNames.Any(v => v.Equals(nameAttribute.Value))
                    select el;
        // Add the attribute to the columns to show the ECB menu
        foreach (XElement el in fields)
            var attribute = new XAttribute(ListItemMenu, bool.TrueString);
    // Update the view
    string viewXml = root.ToString(SaveOptions.DisableFormatting);

Code should be pretty self explanatory, happy coding! 🙂

Custom Field with ECB

This post describes how you would go about creating a new SharePoint field and control the URL it maps to and have it display the ECB (Edit Control Block) menu for the selected item.

Edit Control Block

It may look like an ordinary field with an ECB but using a custom field we can control where clicking the URL takes the user.
Read more


Get every new post delivered to your Inbox

Join other followers: