Guess people need some experience with Linq-to-xml and knowledge of the build of a openXML word document.
I have this Linq to XML query that's supposed to find Content Controls. It works most of the time but I think it's still just juryrigged and not proper.
How it works, if I understand correctly, is that it checks StdRuns and finds if it's properties include one named Tag.
Problem is that Content Controls are perhaps not necceserily a part of a RUN. For example if it's added first in a line. I don't wan't to hit problems later on so I wonder if there is any better way of hitting all Content Controls using linq.
This is hwo the Linq query is now:
var cont = from sdt in document.MainDocumentPart.RootElement.Descendants<SdtRun>()
let sdtPr = sdt.GetFirstChild<SdtProperties>()
let tag = (sdtPr == null ? null : sdtPr.GetFirstChild<Tag>())
where tag != null
select new
{
SdtProps = sdtPr,
TagName = tag.GetAttribute("val", sdt.NamespaceUri).Value
};
Thanks in advance.