I am using Word and OpenXml to provide mail merge functionality in a C# ASP.NET web application:
1) A document is uploaded with a number of pre-defined strings for s
As an addenda to the above; what's perhaps more useful is finding content controls that have been tagged (using the word GUI). I recently wrote some software that populated document templates that contained content controls with tags attached. To find them is just an extension of the above LINQ query:
var mainDocument = doc.MainDocumentPart.Document;
var taggedContentControls = from sdt in mainDocument.Descendants()
let sdtPr = sdt.GetFirstChild()
let tag = (sdtPr == null ? null : sdtPr.GetFirstChild())
where (tag != null)
select new
{
SdtElem = sdt,
TagName = tag.GetAttribute("val", W).Value
};
I got this code from elsewhere but cannot remember where at the moment; full credit goes to them.
The query just creates an IEnumerable of an anonymous type that contains the content control and its associated tag as properties. Handy!