Some code to add the ECB menu to the specified columns of a view:
public void SetEcbColumnOnView(SPView view, List 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 fields = from el in root.Elements(ViewFields).DescendantNodes().OfType()
where el.Attribute(ListItemMenu) != null
// 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()
let nameAttribute = el.Attribute(AttributeName)
where nameAttribute != null && internalNames.Any(v => v.Equals(nameAttribute.Value))
// 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! 🙂
Thought I’d share a class I use for performance monitoring to help identify areas of code that are causing bottlenecks or take a lengthy time to execute.
In SharePoint we can use the SPMonitoredScope class to wrap areas of code that we want to be monitored.
using (new SPMonitoredScope("SharePoint Performance"))
// SharePoint related code
This will output performance logging statistics to the developer dashboard (if enabled) and to the ULS.
For general SharePoint performance logging, SPMonitoredScope is ideal but it only logs methods calls to the SharePoint databases. The class I developed allows you to monitor any method, whether it’s SharePoint related or not.
Areas you might use the custom performance monitoring class would include calls to a custom database, web services or any potentially long running method calls.
Looking for a PowerShell script to restart important services across a SharePoint farm? Look no further because all you need is here 🙂
The script below, initiated by calling the Restart-Services function, restarts the following services on all SharePoint servers in the farm:
- SharePoint Timer
- World Wide Web Publishing Service
- IIS Admin Service
- SharePoint Administration
In is a lesser known CAML operator that I’d like to bring to more peoples attention. When writing CAML and you want to restrict the results by a multi value field equaling two or more values, you’d write something like:
<fieldref Name="Country"></fieldref><values><value Type="LookupMulti">Scotland</value></values>
<fieldref Name="Country"></fieldref><values><value Type="LookupMulti">England</value></values>
<fieldref Name="Country"></fieldref><values><value Type="LookupMulti">Wales</value></values>
<fieldref Name="Country"></fieldref><values><value Type="LookupMulti">Ireland</value></values>
This will return any item that has the value Scotland, England, Wales or Ireland in the Country field. As the number of values you want to match against grows, imagine the state of the CAML query!
With the next version on SharePoint due sometime during the second half of this year, it’s good to hear that Microsoft are still very much continuing to provide an on-premise version. There’s been a lot of chatter recently about this being discontinued but it’s still a kicking and a screaming. See this post from earlier today – Evolution of SharePoint; definitely worth a read.