This project has moved. For the latest updates, please go here.

Set LastWriteTime, when we change custom property

Nov 30, 2011 at 9:33 AM

Hi,

Issue:

1) Open the word document.

2) Set the custom property through code.

3) Do not make any changes in the word document.

4) Click on save button and close the document.

Word document last write is not modified.

Is it possible to modify the last write time of an open word document? If yes, then please share the code.

or any other method to set the last write time property.

Thanks in advance.

Coordinator
Nov 30, 2011 at 11:26 AM

you mean the standard last write property from any file in windows?
in this case use the FileInfo class from .NET.
a nice tutorial you find here: http://www.dotnetperls.com/fileinfo
if you want to change the last write document property from word you have
to perform a dumy action and undo the action immediately.

*mata ne
Sebastian

Dec 1, 2011 at 5:22 AM

Hello Sebastian,

Thanks for the reply. I tried using FileInfo class to change the property but I cannot change its last write time property when the word document is open ("Access Denied").

I am opening a file through Netoffice library and I have a form, in which we can set few custom document properties. After checking few properties, when I go to custom properties window if word, it shows me the correct value of custom properties. That means there is no problem with the saving of custom properties. Now I save and close("without entering any text") the document still the last modified time or last write is not changed.

When I open a word document normally and follow the above steps. It changes the last modify time or last write time.

Is there any way to achieve the same thing with Netoffice library?

It's a very high priority issue for me..Thanks in advance.

Coordinator
Dec 1, 2011 at 9:16 AM

please show me a little bit code, specialy the save code for the document. 

Dec 1, 2011 at 12:19 PM

Hello Sebastian,

Code snippet of, opening a file through Netoffice library.

 

Private m_Word As NetOffice.WordApi.Application = Nothing

 Dim fi As New System.IO.FileInfo(TempTemplateFilePath)
      If (fi.Length > 0) Then
        oRet = m_Word.Documents.Open(TempTemplateFilePath)
After opening a document, I have a form in which we can set custom document properties like postpone merge.
Code snippet when we check some custom document property.
 If (ReadDocumentProperty(cnt.Name) Is Nothing) Then
                m_Properties.Add(cnt.Name, False, propType, oValue, Nothing) ' Berend .Net/982 'DWNET/1115-Sunny
              Else
                m_Properties(cnt.Name).Value = oValue ' Berend .Net/982
              End If
In the above code snippet "m_Properties" is object of DocumentProperties

 

 Private m_Properties As DocumentProperties

 

Custom document properties saved successfully, I have cross checked with Office 2007: Prepare-->Properties--> Document Properties--> Advanced Properties--> Custom tab

 

Now, I save and close the document without doing any changes in the open document. When I open the same document then the changes I made for document properties are not saved. This is because, Date modified is not updated.

Even after calling save() method still it is not updating the modified date. Is there way to modify the date, when we set document property for open document?

I don't want to fix this issue by adding space and immediately removing it.

 

 

 

Coordinator
Dec 1, 2011 at 1:11 PM

the problem is document.Save and document.SaveAs overwrite the BuiltInDocumentProperties.
you can see that in the debugger, after Saves the LastSaveTime property has the current date.
do you use the BuiltInDocumentProperties collection or CustomProperties collection ?

Dec 2, 2011 at 4:02 AM

Hello Sebastian,

I am using CustomProperties collection, following is the code snippet for the same:

 m_oDocProperties.CustomProperties = CType(doc.CustomDocumentProperties, DocumentProperties)
          Client.DocPropertiesForm.DocProperties = m_oDocProperties

Thanks