tags:

views:

321

answers:

1

I have a Word 2007 doc with content control, title and tag set to "Control1" and the value "X". I am trying to change the value of Control1 to "Y"

  string sdtName = "Control1";
  SdtBlock sdt = mainPart.Document.Descendants<SdtBlock>()
            .Where(s =>
            s.GetFirstChild<SdtProperties>().GetFirstChild<Alias>().Val.Value
            .Equals(sdtName)).First();

  Response.Write(sdt.InnerXml);
  //results in X
  sdt.InnerXml = "Y";

X is displayed correctly, but when the InnerXml is set to "Y" it results in X being deleted from the document

A: 

The problem is OpenXML is a piece of crap. If the StdBlock gets moved your Linq Query will fail.

douchebaggery