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]()
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(sNewFile,
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 byEWoodruffWednesday, September 01, 2010 7:17 PM