New Certifications

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 🙂

Posted in General, SharePoint | Tagged | Leave a comment

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 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
                                    select el;

    // Remove the ECB Menu from all columns that currently use it.
    foreach (XElement el in fields)
    {
        el.Attributes(ListItemMenu).Remove();
    }

    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))
                    select el;

        // Add the attribute to the columns to show the ECB menu
        foreach (XElement el in fields)
        {
            Console.WriteLine(el);
            var attribute = new XAttribute(ListItemMenu, bool.TrueString);
            el.Add(attribute);
        }
    }

    // Update the view
    string viewXml = root.ToString(SaveOptions.DisableFormatting);
    view.SetViewXml(viewXml);
    view.Update();
}

Code should be pretty self explanatory, happy coding! 🙂

Posted in SharePoint | Tagged , | Leave a comment

Performance Monitoring Class

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.

Continue reading
Posted in SharePoint | Tagged , | Leave a comment

Restart Services Script

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

Continue reading

Posted in SharePoint | Tagged , | Leave a comment

Alternate to CAML Or

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:

<where>
<or>
  </or><or>
    <eq>
      <fieldref Name="Country"></fieldref><values><value Type="LookupMulti">Scotland</value></values>
    </eq><eq>
    </eq><eq>
      <fieldref Name="Country"></fieldref><values><value Type="LookupMulti">England</value></values>
    </eq><eq>
  </eq></or>
  <or>
    <eq>
      <fieldref Name="Country"></fieldref><values><value Type="LookupMulti">Wales</value></values>
    </eq><eq>
    </eq><eq>
      <fieldref Name="Country"></fieldref><values><value Type="LookupMulti">Ireland</value></values>
    </eq><eq>
  </eq></or>
 
</where>

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!
Continue reading

Posted in SharePoint | Tagged , | Leave a comment