2
votes

From what I understand, when you open, edit, then close an OpenXML document such as an .DOCX file, the revised document is automatically saved. If you change your mind and decide not to save the edits, is there a way to close the document without saving? I can't seem to find anything.

1
Hah! Good detective work. A question about your Answer, though: Does this work both with or without the using block? Your answer implies "without", but as it's a setting for the Open method I'd think with would also be possible?Cindy Meister
I believe it would work the same with or without a using block. Dispose would be called as usual, but because AutoSave is false, it would not save.Len White

1 Answers

3
votes

The document has an AutoSave property, which is set to True by default. The Open method can take an OpenSettings object, which can be used to override the default behavior:

        Imports DocumentFormat.OpenXml.Wordprocessing

        Dim os As OpenSettings = New OpenSettings()
        os.AutoSave = False
        Dim doc as Doc = WordprocessingDocument.Open(Path, True, os)

In this case, the document will not be saved unless doc.Save is called. doc.Dispose will simply release the resources without the save.