Launch a doc file with Process.Start(my.doc), need to know when the file is closed.

  • Thread starter Thread starter Tony
  • Start date Start date
T

Tony

I'm storing documents and images in a client database.

I want to be able to launch a document or image into the proper application
that can view or modify the object. I do this by copying the object from the
database to the temp directory then calling Process.Start(filename) which
launches the correct application and displays the file - all works great.



My problem now is, I want to know when the application is finished with the
file so I can prompt the user and ask if they want to store the changes (if
any) back in the database (similar to how outlook works when editing an
attachment).



I know I can use SystemFileWatcher to be notified when the file is written
to but that could happen more than once (intermediate saves) while the user
is editing the file. I only want to prompt the user once. It doesn't have an
event to see when the file is closed, just modified, etc.



Also, I need to clean up the temp file when the user is done with it but I
don't know how to detect when the user shuts down the process that is
viewing the file (I don't even know which process is being used or if it's
using a shared process (in the case of Excel) or it's own in the case of
Word, etc.



Does anyone know how to detect when a file is closed or know another way to
deal with this issue?



Any info would be greatly appreciated.


Tony
 
I'm sorry I don't have a complete answer but this will get you going anyhow.
There is a way to ask the Process object if they process has terminated.
This is how you will know if they have closed the application. I think it's
process.status that you look at. Sorry for not being more complete, just
sharing my two cents.

Chris
 
¤ I'm storing documents and images in a client database.
¤
¤ I want to be able to launch a document or image into the proper application
¤ that can view or modify the object. I do this by copying the object from the
¤ database to the temp directory then calling Process.Start(filename) which
¤ launches the correct application and displays the file - all works great.
¤
¤
¤
¤ My problem now is, I want to know when the application is finished with the
¤ file so I can prompt the user and ask if they want to store the changes (if
¤ any) back in the database (similar to how outlook works when editing an
¤ attachment).
¤
¤
¤
¤ I know I can use SystemFileWatcher to be notified when the file is written
¤ to but that could happen more than once (intermediate saves) while the user
¤ is editing the file. I only want to prompt the user once. It doesn't have an
¤ event to see when the file is closed, just modified, etc.
¤
¤
¤
¤ Also, I need to clean up the temp file when the user is done with it but I
¤ don't know how to detect when the user shuts down the process that is
¤ viewing the file (I don't even know which process is being used or if it's
¤ using a shared process (in the case of Excel) or it's own in the case of
¤ Word, etc.
¤
¤
¤
¤ Does anyone know how to detect when a file is closed or know another way to
¤ deal with this issue?
¤

One thing you can try is handling the Close event from the automation client:

How To Handle Events for Microsoft Word Using Microsoft Visual Basic .NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;302816


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Will not be using automation and not guaranteed that it will be an office
application that is launched, can be of any file type.

I think the Process object returned from Process.Start() will work for me.

Thanks,
Tony
 
Back
Top