IgorP

Hello,

I am trying to open a word document, using the following code:

Word.Application app = new Word.Application();
Word.Document doc = new Word.Document();

doc = app.Documents.Open(ref fileName,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing);

After I am finished, I close the document and file using:

doc.Close(ref missing, ref missing, ref missing);
app.Quit(ref missing, ref missing, ref missing);

The problem is, that more than one WINWORD.EXE process is opened, executing code above (I don't know why).

After I call the close code, only one WINWORD.EXE is closed.

Sometimes the WINWORD.EXE is not even opened (the program just freezes in the line, Documents.Open line.

Oh, yes. Before I forget. There is one more simptom, which is also mentioned in the title of the post. If I manage to open document I am trying to open, a MessageBox pops up, saying me, that the 'file is in use' and asking me, what should be done (open read only, open locale, ...)


Re: Visual Studio Tools for Office [C#] [VSTO Word] File in use

IgorP

Btw. forgot to mention.

I am using:
. Windows Vista
- VSTO for VS 2005 and Office 2007
- Office 2007




Re: Visual Studio Tools for Office [C#] [VSTO Word] File in use

Phil Hoff - MSFT

Are you doing this from within a Word VSTO add-in or a standalone application If the former, then the creation and the quitting of the Word Application object is unnecessary. The add-in already has an Application property that allows access to the Word object model and the lifetime of the add-in will be managed for you.

Furthermore, you should not open a document with the new keyword. Instead, simply assign the result of the Application.Documents.Open() method to a variable. For example:

Word.Document doc = Application.Documents.Open(ref fileName,

ref missing, ref missing, ref missing, ref missing, ref missing,

ref missing, ref missing, ref missing, ref missing, ref missing,

ref missing, ref missing, ref missing, ref missing, ref missing);

...

doc.Close(ref missing, ref missing, ref missing);

-Phil