J
John Smith
Hey folks,
I've got a Windows C# application that generates a .doc file and then allows
the user to preview it.
I generate the file using the StreamWriter class and do a flush() and a
close() after writing the last line (which always get runned).
Because the intended users have all versions of MS Word ranging from Word 97
to 2003, I chose not to go with a dll object modeling approach and instead
to embed a WebBrowser control and open the document in there. My code for
doing this comes from the MS example on MSDN.
Problem is, sometimes (randomly), after running the program the file that is
created remains locked by MS Word and cannot be overwritten and can only be
opened readonly. Task Manager shows WinWord still running. If I kill it in
TaskManager, the file is free again. Other times it works fine and none of
this happens. The data written to the file is always the same, so it's not
something going on there, and the lines of code executed are always the
same.
What do you think could be causing this to occur and how can I ensure that
the file is released and WinWord closes after the form with the WebBrowser
control closes?
Thanks!
I've got a Windows C# application that generates a .doc file and then allows
the user to preview it.
I generate the file using the StreamWriter class and do a flush() and a
close() after writing the last line (which always get runned).
Because the intended users have all versions of MS Word ranging from Word 97
to 2003, I chose not to go with a dll object modeling approach and instead
to embed a WebBrowser control and open the document in there. My code for
doing this comes from the MS example on MSDN.
Problem is, sometimes (randomly), after running the program the file that is
created remains locked by MS Word and cannot be overwritten and can only be
opened readonly. Task Manager shows WinWord still running. If I kill it in
TaskManager, the file is free again. Other times it works fine and none of
this happens. The data written to the file is always the same, so it's not
something going on there, and the lines of code executed are always the
same.
What do you think could be causing this to occur and how can I ensure that
the file is released and WinWord closes after the form with the WebBrowser
control closes?
Thanks!