0
votes

Using WordprocessingDocument to modify .docx files, but the Date modified of the file is always changed after disposing the file even if no changes are made.

I've tried to disable AutoSave - date is still modified.

This piece of code leads to change of the date

using(var document = WordprocessingDocument.Open(filePath, true, new OpenSettings { AutoSave = false }))
{
}

Is there any way to avoid changes to the Date modified of the file when no changes are actually made?


Env: NET Core 3.0, Open xml sdk, Nuget version 2.9.1

1
Why are you opening the file in editable mode if you don't want to change it? See the second argument, set it to false. - Kuba hasn't forgotten Monica
@KubaOber I need to compare single paragraph from the document with external resource and replace it in the document if there is change. - vasil oreshenski
@KubaOber Yes, disabling the editing mode did not change 'date modified' of the file. Opening the file twice will be the easiest way to go. Thanks for the help :) - vasil oreshenski

1 Answers

2
votes

You need to first open in non-editable mode, do the comparison, and then reopen in editable mode should there be a need to change the file.