Search code examples
c#powerpointopenxml

Can't access SlideMasterPart in PowerPoint using OpenXml


I am trying to create a pptx file on the fly using this OpenXml tutorial.

I am getting the error:

'System.Collections.Generic.IEnumerable' does not contain a definition for 'First' and no extension method 'First' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?)

on the following line:

var slideMasterPart = presentationPart.SlideMasterParts.First();

Is there a workaround?


Solution

  • Add the reference to using System.Linq;

    By way of explanation, the First() method is an extension method that lives in the System.Linq namespace and is applied to anything that inherits from IEnumerable. See the MSDN docs Enumerable.First Method and System.Linq Namespace for more info.