Group:  Microsoft Word ยป microsoft.public.word.oleinterop
Thread: how to detect a word document changed or not changed

Geek News

how to detect a word document changed or not changed
Erkav 5/17/2007 1:30:01 PM
Hi,
i developed a program in C# 2.0 with office 2003 PIAs. I try to detect a
word document has been changed or not. I try to check a word document file
hash codes before open and after close. Even the document has not been
changed but these two hash code always different. And also document before
opening and after opening hash codes are different too. I tried to check
content property of word documents but i met same result. How can i detect a
word document has been really changed?

Thanks.
Re: how to detect a word document changed or not changed
"Doug Robbins - Word MVP" <dkr[ at ]REMOVECAPSmvps.org> 5/17/2007 3:00:02 PM
Make use of the Document.Saved property.

It returns True if the specified document or template has not changed since
it was last saved. False if Microsoft Word displays a prompt to save changes
when the document is closed. It is a Read/write Boolean property.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Erkav" <Erkav[ at ]discussions.microsoft.com> wrote in message
news:A44DD7F1-0DD8-4229-8B68-49CF54CDF929[ at ]microsoft.com...
[Quoted Text]
> Hi,
> i developed a program in C# 2.0 with office 2003 PIAs. I try to detect a
> word document has been changed or not. I try to check a word document file
> hash codes before open and after close. Even the document has not been
> changed but these two hash code always different. And also document before
> opening and after opening hash codes are different too. I tried to check
> content property of word documents but i met same result. How can i detect
> a
> word document has been really changed?
>
> Thanks.


Re: how to detect a word document changed or not changed
Erkav 5/30/2007 9:32:00 AM
Thanks for your reply Doug.
But your suggestion doesn't solve my problem. May i give some details about
my application.
My application is a little member of a Document Management System. It' s a
client that developed to open files that store in DMS. Application hasn't got
a UI. It is only downloads the files from a web service of DMS and serves to
operating system to open files with default viewer that defined in OP. My app
takes file hash code before open it after than waits to close application
that launched by OP. Finally my app takes file hash code and compares these 2
hash codes. If hash codes are different, my app uploads the file to DMS as a
new version of file via web service. But this algorithm doesn't work for Word
files as i tried to describe on my previous post. On the other hand, my app
have some specifications for Word documents. It opens file that has ".doc"
extension with office PIAs to load some checks and to load some special
toolbar buttons. It handles some Word application events to run its
subcontrols. Now, how should i find out the document exactly not changed.
When i handle Word.BeforeDocumentClose event, if user clicks the save button
before closing document, Document.Saved property set true and the document' s
last version different from the first version. My app has to perceive that
difference.

"Doug Robbins - Word MVP" wrote:

[Quoted Text]
> Make use of the Document.Saved property.
>
> It returns True if the specified document or template has not changed since
> it was last saved. False if Microsoft Word displays a prompt to save changes
> when the document is closed. It is a Read/write Boolean property.
>
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "Erkav" <Erkav[ at ]discussions.microsoft.com> wrote in message
> news:A44DD7F1-0DD8-4229-8B68-49CF54CDF929[ at ]microsoft.com...
> > Hi,
> > i developed a program in C# 2.0 with office 2003 PIAs. I try to detect a
> > word document has been changed or not. I try to check a word document file
> > hash codes before open and after close. Even the document has not been
> > changed but these two hash code always different. And also document before
> > opening and after opening hash codes are different too. I tried to check
> > content property of word documents but i met same result. How can i detect
> > a
> > word document has been really changed?
> >
> > Thanks.
>
>
>
Re: how to detect a word document changed or not changed
Erkav 5/30/2007 9:33:01 AM
Thanks for your reply Doug.
But your suggestion doesn't solve my problem. May i give some details about
my application.
My application is a little member of a Document Management System. It' s a
client that developed to open files that store in DMS. Application hasn't got
a UI. It is only downloads the files from a web service of DMS and serves to
operating system to open files with default viewer that defined in OP. My app
takes file hash code before open it after than waits to close application
that launched by OP. Finally my app takes file hash code and compares these 2
hash codes. If hash codes are different, my app uploads the file to DMS as a
new version of file via web service. But this algorithm doesn't work for Word
files as i tried to describe on my previous post. On the other hand, my app
have some specifications for Word documents. It opens file that has ".doc"
extension with office PIAs to load some checks and to load some special
toolbar buttons. It handles some Word application events to run its
subcontrols. Now, how should i find out the document exactly not changed.
When i handle Word.BeforeDocumentClose event, if user clicks the save button
before closing document, Document.Saved property set true and the document' s
last version different from the first version. My app has to perceive that
difference.

"Doug Robbins - Word MVP" wrote:

[Quoted Text]
> Make use of the Document.Saved property.
>
> It returns True if the specified document or template has not changed since
> it was last saved. False if Microsoft Word displays a prompt to save changes
> when the document is closed. It is a Read/write Boolean property.
>
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "Erkav" <Erkav[ at ]discussions.microsoft.com> wrote in message
> news:A44DD7F1-0DD8-4229-8B68-49CF54CDF929[ at ]microsoft.com...
> > Hi,
> > i developed a program in C# 2.0 with office 2003 PIAs. I try to detect a
> > word document has been changed or not. I try to check a word document file
> > hash codes before open and after close. Even the document has not been
> > changed but these two hash code always different. And also document before
> > opening and after opening hash codes are different too. I tried to check
> > content property of word documents but i met same result. How can i detect
> > a
> > word document has been really changed?
> >
> > Thanks.
>
>
>
Re: how to detect a word document changed or not changed
"Doug Robbins - Word MVP" <dkr[ at ]REMOVECAPSmvps.org> 6/10/2007 12:27:04 AM
Maybe you will need to try and make use of the Document.Compare.Method to
determine if any revisions have been made to the document.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Erkav" <Erkav[ at ]discussions.microsoft.com> wrote in message
news:E8343B3E-132C-40E2-B183-685BDC99B3DE[ at ]microsoft.com...
[Quoted Text]
> Thanks for your reply Doug.
> But your suggestion doesn't solve my problem. May i give some details
> about
> my application.
> My application is a little member of a Document Management System. It' s a
> client that developed to open files that store in DMS. Application hasn't
> got
> a UI. It is only downloads the files from a web service of DMS and serves
> to
> operating system to open files with default viewer that defined in OP. My
> app
> takes file hash code before open it after than waits to close application
> that launched by OP. Finally my app takes file hash code and compares
> these 2
> hash codes. If hash codes are different, my app uploads the file to DMS as
> a
> new version of file via web service. But this algorithm doesn't work for
> Word
> files as i tried to describe on my previous post. On the other hand, my
> app
> have some specifications for Word documents. It opens file that has ".doc"
> extension with office PIAs to load some checks and to load some special
> toolbar buttons. It handles some Word application events to run its
> subcontrols. Now, how should i find out the document exactly not changed.
> When i handle Word.BeforeDocumentClose event, if user clicks the save
> button
> before closing document, Document.Saved property set true and the
> document' s
> last version different from the first version. My app has to perceive that
> difference.
>
> "Doug Robbins - Word MVP" wrote:
>
>> Make use of the Document.Saved property.
>>
>> It returns True if the specified document or template has not changed
>> since
>> it was last saved. False if Microsoft Word displays a prompt to save
>> changes
>> when the document is closed. It is a Read/write Boolean property.
>>
>>
>> --
>> Hope this helps.
>>
>> Please reply to the newsgroup unless you wish to avail yourself of my
>> services on a paid consulting basis.
>>
>> Doug Robbins - Word MVP
>>
>> "Erkav" <Erkav[ at ]discussions.microsoft.com> wrote in message
>> news:A44DD7F1-0DD8-4229-8B68-49CF54CDF929[ at ]microsoft.com...
>> > Hi,
>> > i developed a program in C# 2.0 with office 2003 PIAs. I try to detect
>> > a
>> > word document has been changed or not. I try to check a word document
>> > file
>> > hash codes before open and after close. Even the document has not been
>> > changed but these two hash code always different. And also document
>> > before
>> > opening and after opening hash codes are different too. I tried to
>> > check
>> > content property of word documents but i met same result. How can i
>> > detect
>> > a
>> > word document has been really changed?
>> >
>> > Thanks.
>>
>>
>>


Re: how to detect a word document changed or not changed
Erkav 6/26/2007 6:46:01 PM
I achieved to solve this problem to take hash code with the following lines:

public int ComputeHash() {
System.Security.Cryptography.HashAlgorithm hashAlgorithm =
System.Security.Cryptography.HashAlgorithm.Create();
FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] fileHash = hashAlgorithm.ComputeHash(fs);
fs.Close();
return BitConverter.ToInt32(fileHash, 0);
}



"Doug Robbins - Word MVP" wrote:

[Quoted Text]
> Maybe you will need to try and make use of the Document.Compare.Method to
> determine if any revisions have been made to the document.
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "Erkav" <Erkav[ at ]discussions.microsoft.com> wrote in message
> news:E8343B3E-132C-40E2-B183-685BDC99B3DE[ at ]microsoft.com...
> > Thanks for your reply Doug.
> > But your suggestion doesn't solve my problem. May i give some details
> > about
> > my application.
> > My application is a little member of a Document Management System. It' s a
> > client that developed to open files that store in DMS. Application hasn't
> > got
> > a UI. It is only downloads the files from a web service of DMS and serves
> > to
> > operating system to open files with default viewer that defined in OP. My
> > app
> > takes file hash code before open it after than waits to close application
> > that launched by OP. Finally my app takes file hash code and compares
> > these 2
> > hash codes. If hash codes are different, my app uploads the file to DMS as
> > a
> > new version of file via web service. But this algorithm doesn't work for
> > Word
> > files as i tried to describe on my previous post. On the other hand, my
> > app
> > have some specifications for Word documents. It opens file that has ".doc"
> > extension with office PIAs to load some checks and to load some special
> > toolbar buttons. It handles some Word application events to run its
> > subcontrols. Now, how should i find out the document exactly not changed.
> > When i handle Word.BeforeDocumentClose event, if user clicks the save
> > button
> > before closing document, Document.Saved property set true and the
> > document' s
> > last version different from the first version. My app has to perceive that
> > difference.
> >
> > "Doug Robbins - Word MVP" wrote:
> >
> >> Make use of the Document.Saved property.
> >>
> >> It returns True if the specified document or template has not changed
> >> since
> >> it was last saved. False if Microsoft Word displays a prompt to save
> >> changes
> >> when the document is closed. It is a Read/write Boolean property.
> >>
> >>
> >> --
> >> Hope this helps.
> >>
> >> Please reply to the newsgroup unless you wish to avail yourself of my
> >> services on a paid consulting basis.
> >>
> >> Doug Robbins - Word MVP
> >>
> >> "Erkav" <Erkav[ at ]discussions.microsoft.com> wrote in message
> >> news:A44DD7F1-0DD8-4229-8B68-49CF54CDF929[ at ]microsoft.com...
> >> > Hi,
> >> > i developed a program in C# 2.0 with office 2003 PIAs. I try to detect
> >> > a
> >> > word document has been changed or not. I try to check a word document
> >> > file
> >> > hash codes before open and after close. Even the document has not been
> >> > changed but these two hash code always different. And also document
> >> > before
> >> > opening and after opening hash codes are different too. I tried to
> >> > check
> >> > content property of word documents but i met same result. How can i
> >> > detect
> >> > a
> >> > word document has been really changed?
> >> >
> >> > Thanks.
> >>
> >>
> >>
>
>
>

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net