Save editing changes to a Word document RRS feed

  • Question

  • I need help (a good sample) for this one: How to save changes in word documents.  All I want to do is open a document and change the attribute value on the sdrPr element  "alias" from "content" to "paragraph" and then save the document. But when I call Close it doesn't save the changes. I must be missing something but can't find any information on how to do this.

     OpenSettings openSettings = new OpenSettings();
     openSettings.AutoSave = true;
     using (WordprocessingDocument wordDoc = 
        WordprocessingDocument.Open(inputFilePath + fileName, 
         FileAccess fa = wordDoc.FileOpenAccess;
         var controls = wordDoc.MainDocumentPart
                  .Descendants(w + "sdt")
                        .Where(elm => ((string)elm.Elements(w + "sdtPr")
                                .Elements(w + "alias")
                                .Attributes(w + "val")
                                .FirstOrDefault()).ToLower() == "content");
         foreach (var control in controls)
             XElement alias = control
                    .XPathSelectElement("w:sdtPr",  nsm)
                    .XPathSelectElement("w:alias", nsm);
             alias.SetAttributeValue(w + "val", "paragraph");





    Saturday, October 22, 2011 6:49 PM

All replies

  • Hi Rob

    I split this off from an FAQ post you made back in October. Have you received an answer to this question already?

    Cindy Meister, VSTO/Word MVP
    Wednesday, January 4, 2012 8:01 AM