Deleting DOC file in Shutdown Event

C

Chuck Hartman

I have created a VSTO 2005 Word project that opens a remote read-only
document. The Open Event handler does a SaveAs of the current document to a
local temporary folder to allow the user to make changes to the document.
When the user finishes with their changes, they use an Actions Pane button to
save the document and post it back to the server. This all works well without
any problems.

For security reasons, I would like to clean up all of the temporary
resources created by my project, which among other things includes the DOC
file saved during the Open Event handler. However, even if I wait until the
VSTO Shutdown event, which occurs after the Close event, I am unable to
delete the file because it is still locked by Word. Is there a way to get
Word to unlock the file so it can be deleted, or is there some other way to
get rid of that file? Thanks.

This doesn't seem to be a VSTO specific question, so I am posting here.
Please let me know if there is a more appropriate group.
 
W

Word Heretic

G'day "Chuck Hartman" <[email protected]>,

Only if you do it from outside Word altogether, thus being able to
shutdown Word. Tis very annoying. Next best solution is to delete all
the temp doc content so at least the tmp file is very small, and
advise users of your software to regularly clean the appropriate
folder.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Chuck Hartman reckoned:
 
C

Chuck Hartman

Steve,

Thanks, I have tried this and it ALMOST works. Even after all of the
document content is deleted and the file is saved again, Word does not see
the deleted content with the document is re-opened, but some of the deleted
content is still discoverable from the file on disk (e.g. with Notepad).
 
W

Word Heretic

G'day Chuck Hartman <[email protected]>,

Yeah. You could try an undo clear after that final delete, but even
then doco corruption can leave fragments around.

What about if you close the document, and create a new one then save
with the same filename. That might work.


Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Chuck Hartman reckoned:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top