Word interop

C

Chuck Norris

Hi everybody,
A question about how to use 'Microsoft.Office.Interop.Word'.
I'm trying the following code:

Application app = new Word.ApplicationClass();
Document doc = app.Documents.Open(ref templateFile,...);
//...
//replace bookmarks...
//...
doc.SaveAs(ref newFile,...);
doc.Close(...);
doc.Quit(...);

It works very well but when the templateFile is already opened in
another Word instance,
the following dialog box appears in my .NET app.:
If few word the box says:

"File already in use", the templateFile is blocked.
Then 3 radiobuttons to make a choice:
- open a read-only copy
- create a local copy
- wait until the file is ready

Now I don't want this dialog box to appear, I want my app to work even
if the templateFile is already opened,
because the template remains unchanged in any case and the app always
saves a copy of it.

Someone can help me!

Thanks,
Bye.
 
W

wisccal

Hi,

You can specifically request to open the doc in read-only mode like
so:

Document doc = app.Documents.Open(ref templateFile, Type.Missing,
true, ...); //3rd param specifies read-only mode if true

That should do away with the dialog.
 
C

Chuck Norris

It works fine.
Thanks a lot!

Bye.




Hi,

You can specifically request to open the doc in read-only mode like
so:

Document doc = app.Documents.Open(ref templateFile, Type.Missing,
true, ...); //3rd param specifies read-only mode if true

That should do away with the dialog.
 

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