This project has moved and is read-only. For the latest updates, please go here.

Add Tags "property" to Docx class;

Apr 1, 2015 at 3:07 PM
It be cool if you would add ability to manipulate MS Word Controls tags, which can be created through MS Word Application \ "Developer" Tab \ { Text Control | RTF Control | Image Control | ... }.
This will be very usefull in creating documents via template.

I have to use such code:
public static void SetMSWordTagValuesByName(DocX doc, string tagName, string newValue) {
            System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument();
            System.Xml.XmlNamespaceManager xmlnsManager = new System.Xml.XmlNamespaceManager(xdoc.NameTable);
            xmlnsManager.AddNamespace("w", "");

            XmlNodeList sdtNodes = xdoc.SelectNodes(String.Format("//w:sdt[w:sdtPr/w:tag/@w:val = \"{0}\"]", tagName), xmlnsManager);
            foreach (XmlNode sdt in sdtNodes) {
                sdt.SelectNodes("w:sdtContent/w:r/w:t", xmlnsManager).OfType<XmlNode>().ToList().ForEach(n => n.InnerText = newValue);
            // replaces XDoc object xml-body to new one (with filled Word-Controls)
            using (var r = doc.Xml.CreateWriter()) {
                r.WriteNode(xdoc.CreateNavigator(), true);
Apr 1, 2015 at 3:11 PM
In COMInterop I can simply do:
Word._Document oDoc = procWord.Documents.Add(MainForm.TEMPLATE_FULL_NAME);    //open document as template   
oDoc.SelectContentControlsByTag("Name_IP")[1].Range.Text = txtName.Text;
I would want to write such simple code via DocXlib.dll.