Word API and Stream object process clashing in .NET : (Urgent) please help!!

R

Raj

Hi,
I am facing a problem in my .NET code. I have a global
class in which I have a function that opens the word
application, creates a document in the specified location.
Then I say word.quit and return true to the calling
appliation.

In my code behind file, I call this global function to
create the doc. After the global function returns true, I
use the stream object to read the data(from the newly
created word document) into a variable of type byte.

The problem occurs at this stage when I use the stream
object to open the document and read the contents. The
exception error being shown is "The document cannot be
accessed as it is being used by another process".

What I could understand is that the word application is
still accessing this document while I try to open with the
stream object. So the 2 processes conflict. I tried
introducing some delay in between this but still at lot of
times it shows the error. It behaves absurdly!!

PLease let me know how can I tackle this problem. I am in
a real tight situiation and any help/suggestion will be
greatly appreciated.

With regards,
Rajesh
 
C

Cindy M -WordMVP-

Hi Raj,

If I'm following you correctly, then what you're running into
is the same problem people trying to automate Word have had
since time immemorial (usually trying to delete files). Even
after you've closed Word, there's often still a "file lock"
present. This may persist for only a short time, or it may
hang around until Windows is unloaded.

Are you able to COPY the *.doc file to a "temp" location,
then stream that?
I am facing a problem in my .NET code. I have a global
class in which I have a function that opens the word
application, creates a document in the specified location.
Then I say word.quit and return true to the calling
appliation.

In my code behind file, I call this global function to
create the doc. After the global function returns true, I
use the stream object to read the data(from the newly
created word document) into a variable of type byte.

The problem occurs at this stage when I use the stream
object to open the document and read the contents. The
exception error being shown is "The document cannot be
accessed as it is being used by another process".

What I could understand is that the word application is
still accessing this document while I try to open with the
stream object. So the 2 processes conflict. I tried
introducing some delay in between this but still at lot of
times it shows the error. It behaves absurdly!!

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep
30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 
F

Francis Dion

If you want a quick fix to your problem, don't use the MS-Word
application to create the documents!

Using XpertDoc, you can produce genuine MS-Word documents with loading
MS-Word in memory and shuting it down afterwards, and without having
to concern yourself with remaining locks.

XpertDoc is blazingly fast (it can create hundreds of documents per
seconds!) and you are garanteed that the document is available as soon
as XpertDoc returns from its "Execute" method.

You can check it out at www.xpertdoc.com

Hope this helps!
 

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