It’s been a while and that’s an understatement!! I really do need to get back into the habit of blogging more about my experiences and sharing my knowledge of SharePoint and the related technologies.
I recently decided to sit some exams and go for the MCSD SharePoint Applications, which is comprised of four exams. Seeing as I was going for that I thought it best to also go for the App Builder (previously called Web Applications) which required the first two exams of the SharePoint track plus one for WCF. Happy to report that I passed all five exams and am now certified for both SharePoint Applications and App Builder 🙂
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
// 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))
// 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.
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!