How to Open Word Document

  • Thread starter Thread starter Al
  • Start date Start date
A

Al

Greetings,
I'm trying to open a word document when a command button is clicked. The code below loads Microsoft Word. I can see it in the task manager. When I tried to copy the file, I received an access denied error. So, I believe the document is also loaded.

But, the document is not visible. Can someone tell me what I'm doing wrong? Does anyone have a working code sample.
Thanks in advance for your help.
System.Diagnostics.Process proc = new System.Diagnostics.Process();

proc.EnableRaisingEvents=false;

proc.StartInfo.FileName="winword";

proc.StartInfo.Arguments="D:\\aaa\\bbb\\ccc\\ddd.doc";

proc.Start();


--



Regards,

Al
 
First the good There is nothing wrong with your code.

You write you get an access denied error. Are you sure the file exists and
if so do you have enough rights to open the file? Is the file already opened?

If you are trying this in a webapp. Remember that your application runs with
completly different security settings.
 
Greetings,
Thanks for the reply
Are you sure the file exists and if so do you have enough rights to open
the file?
Yes the file exists. The file is in the web application's folder so I would
think the rights are adequate.
Is the file already opened?
No


My main concern is making the Microsoft Word application visible. Since
it's loaded and in the task manager, how do I make it visible for the user.

Thanks in advance.
--


Regards,

Allen Anderson
 
I get a sense in what you're trying to do.
At this moment you are opening the word document on the serverside.

Couldn't you just redirect to the word-document?
This would ask the user if he want to download or open the word document.
Otherwise you could look into WSE.
 
Inline
Willy.

Al said:
Greetings,
Thanks for the reply

Yes the file exists. The file is in the web application's folder so I
would think the rights are adequate.

No


My main concern is making the Microsoft Word application visible. Since
it's loaded and in the task manager, how do I make it visible for the
user.
Office applications are not designed and not supported to run from web
applications or windows services in general.. It's just plain stupid to
start a word application from a web application when there is a user logged
on, why doesn't he start word himself?
 
Sometimes we do things in large volumes without user input e.g. generate a
custom fax document. Word is very rich and performs reasonable well, as long
as the installation is dedicated to the app. If you got an access denied
error, I can guarantee the file is not open. WINWORD will show in task
manager until you quit regardless of whether a document is open. Typically
the user ASP.Net will try to run Word. You can probably verify this by
checking the security event log on the box hosting the file for the failure
audits. I recommend setting the Microsoft Word Document user in DCOM Config
to a user with rights to the document, maybe even a domain level user. Word
will then always run as this user.
 
Office applications are not designed and not supported to run from web
applications or windows services in general.. It's just plain stupid to
start a word application from a web application when there is a user logged
on, why doesn't he start word himself?

Starting the application himself (on the client side) is exactly what a
redirect does.
--
Marinus Holkema

http://marinusholkema.blogspot.com/
 
Marinus,
Thanks for your helpful replies. I'll have to experiment with redirection.

Thanks again.

--
Regards,

Al
 
John,
Thanks for your helpful replies. I'll have to research DCOM Config.

The word document I'm trying to open executes a Mail Merge. When the
document opens, it automatically requires user input to start the merge.
Basically, click "Yes" to start the mail merge. Could the user input box be
keeping the document in the background.

Thanks again.

--
Regards,

Al

--


Regards,

Allen Anderson
 
It's just plain stupid to start a word application .....

Willy,

Thanks for replying. Unfortunately, you decided to be condescending towards
me.

You don't know me Willy. And your choice of words was unnecessary.

Even still, have a good day.
 
Marinus Holkema said:
Starting the application himself (on the client side) is exactly what a
redirect does.
--

Sorry but this is not what I'm talking about, and is IMO not what the OP is
looking for either, I suppose he knows and requires to have Word running at
the server.

Willy.
 
Hmmm, what's wrong with my choice of words? You ask a question, and I took
some time to reply in an effort to change your mind on what you might try to
achieve. You are trying to use a program in an environment which it wasn't
designed for, if you don't believe me that's ok with me, but there are
others reading these postings and I don't want give the impression that all
is well running office server side, maybe following will help you change
your mind:
http://support.microsoft.com/default.aspx?scid=kb;en-us;257757
Note that the title is a bit misleading, this info not only applies to
server-side 'automation', it also applies to office applications started
(using CreateProcessfrom which is called by Process.Start) from ASP, ASP.NET
or any other Windows service, simply because these applications inherit the
security context and the desktop context of the launching service, that is
they don't have access to the interactive desktop.

Willy.
 
John Hanson said:
Sometimes we do things in large volumes without user input e.g. generate a
custom fax document. Word is very rich and performs reasonable well, as
long
as the installation is dedicated to the app. If you got an access denied
error, I can guarantee the file is not open. WINWORD will show in task
manager until you quit regardless of whether a document is open. Typically
the user ASP.Net will try to run Word. You can probably verify this by
checking the security event log on the box hosting the file for the
failure
audits. I recommend setting the Microsoft Word Document user in DCOM
Config
to a user with rights to the document, maybe even a domain level user.
Word
will then always run as this user.

:


Not sure why you mention DCOM here, the OP isn't using automation, he's
starting Word using Process.Start.
Note also that running Word as whatever user specified in the DCOM
properties, only applies the user token to the process running Word, the
profile of that user isn't necessarily loaded , it's only loaded when the
same user is logged on interactively.

Willy.

Willy.
 
My bad, I didn't read his original code. I agree with the concept of
redirecting to Word, don't do the open programatically unless you really need
to.
 

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

Back
Top