UpdateLastSavedTimeProperty

SaveOptions.UpdateLastSavedTimeProperty property

Gets or sets a value determining whether the LastSavedTime property is updated before saving.

public bool UpdateLastSavedTimeProperty { get; set; }

Examples

Shows how to determine whether to preserve the document’s “Last saved time” property when saving.

Document doc = new Document(MyDir + "Document.docx");

Assert.AreEqual(new DateTime(2021, 5, 11, 6, 32, 0), 
    doc.BuiltInDocumentProperties.LastSavedTime);

// When we save the document to an OOXML format, we can create an OoxmlSaveOptions object
// and then pass it to the document's saving method to modify how we save the document.
// Set the "UpdateLastSavedTimeProperty" property to "true" to
// set the output document's "Last saved time" built-in property to the current date/time.
// Set the "UpdateLastSavedTimeProperty" property to "false" to
// preserve the original value of the input document's "Last saved time" built-in property.
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
saveOptions.UpdateLastSavedTimeProperty = updateLastSavedTimeProperty;

doc.Save(ArtifactsDir + "OoxmlSaveOptions.LastSavedTime.docx", saveOptions);

doc = new Document(ArtifactsDir + "OoxmlSaveOptions.LastSavedTime.docx");
DateTime lastSavedTimeNew = doc.BuiltInDocumentProperties.LastSavedTime;

if (updateLastSavedTimeProperty)
    Assert.That(DateTime.Now, Is.EqualTo(lastSavedTimeNew).Within(1).Days);
else
    Assert.AreEqual(new DateTime(2021, 5, 11, 6, 32, 0), 
        lastSavedTimeNew);

See Also