Error Locating Content Control: No definition for 'Where'


  • I am trying to locate a content control within an .doxc document via VB (or C# to resolve the issue).

    Any time I attempt to add a .Where to my SdtBlock variable definition I get an error (In short):

    'System.Collections.Generic.IEnumerable<DocumentFormat.OpenXml.Wordprocessing.SdtBlock>' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument of type 'System.Collections.Generic.IEnumerable<DocumentFormat.OpenXml.Wordprocessing.SdtBlock>' could be found.

    I have tried everything from re-downloading the most recent version of the Open XML SDK/DLL, rewriting the code in C#, browsed countless websites and references and have found no resolve.

    My code as follows:


    Using wordDoc As WordprocessingDocument = WordprocessingDocument.Open(sNewFile, True)


                   Dim mainPart As MainDocumentPart = wordDoc.MainDocumentPart


                   Dim tblTag As String = "OrderSummary" 


                   Dim ccWithTable As SdtBlock = mainPart.Document.Body.Descendants(Of SdtBlock)().Where(Function(r) r.SdtProperties.GetFirstChild(Of Tag)().Val = tblTag).[Single]()


    End Using



    using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(sNewFile, true))




          MainDocumentPart mainPart = wordDoc.MainDocumentPart;


          string tblTag = "OrderSummary";


          SdtBlock ccWithTable = mainPart.Document.Body.Descendants<SdtBlock>()


            .Where(r => r.SdtProperties.GetFirstChild<Tag>().Val == tblTag).Single();





    Any help would be great. I am new at this and honestly, I do not know where 'r' comes from. I am only assuming that it is a variable that represents a row.

    Thank you in advance!!


    Wednesday, September 01, 2010 11:42 AM


  • Where() is an extension method used in LINQ queries like the one in your code.  You need to add a using/Imports statement for the System.Linq namespace.  It's in the System.Core assembly which your project probably already references but you should check for it and add it if necessary.  Some research on LINQ, extension methods, and llambda expressions should clear up any other questions you might have such as what the "r" is for and where it comes from (it's part of the llamda expression passed to the Where() method).



    • Proposed as answer by EWoodruff Wednesday, September 01, 2010 7:17 PM
    • Marked as answer by Ji.ZhouModerator Thursday, September 09, 2010 3:01 AM
    Wednesday, September 01, 2010 7:17 PM