Creating microsoft word document using C#.net

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using the following code to create word document but the problem is if
you go to task manager you'll see a WINWORD.EXE process is running but not
the application, here is the code:


Word.Document aDoc= WordApp.Documents.Add(ref fileName, ref newTemplate, ref
docType, ref isVisible);
WordApp.Visible = true;
aDoc.Activate();
WordApp.Selection.TypeText("Hello");
WordApp.Selection.ParagraphFormat.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphCenter;
WordApp.Selection.Font.Bold = (int)Word.WdConstants.wdToggle;

any suggestions

thanks
 
Do you want to see the application, or not see the process running at all?

I’m guessing it is the latter, and if that is the case... then the answer is
no.

Word is required for the construction of the document with the code you laid
out, just think, without running word, the interop libraries would need to
know how to act like word, awful needless really, so instead, the interop
provides a way for you to talk to Word and have it do your bidding.

If you are hell bent against having Word run at all... one option is always
to build the Word doc from scratch according to the documentation available
on it.

Brendan
 
Hello Brendan
All what i'm trying to do is launching micosoft word so i can write to it
through the web application but the problem is the code that i wrote just
Initiate the process "WINWORD.EXE" but it won't launch the microsoft word
application
thanks
 
exacltly,i've done before as windows application but its not working as web
application.
thanks
 
Ahh, that makes sense... and is unfortunately not possible, at least not as
you describe it.

The ASP.NET application you are hosting is being served up by a server,
while the client viewing it may have word installed, has it well outside of
the reach of the server. This is of course by design, after all, would you
like any old web page to be able to easily launch applications on your
desktop just because you browsed there?

If you are hell bent on having a web page launch word on the client PC...
one way to do that would be to create a Windows Form control whose sole job
is doing the work with Word that you want. This control would be hosted
within the web page that is served to the client, upon receiving, the client
would download and run the control.

This method is not perfect though, as it would make several key assumptions,
any of which not being true would cause this method to fail.

The two big things you need to make sure of (other than the obvious of
having Word installed), is that the client has the .NET Framework installed,
and that they and the control have sufficient permissions on the PC to
interop with Word and do what you want with it.

Brendan
 
I totally apreciate your help,would you be able to show me an example how you
call a windows form from web application?
thank you.
 
A windows form from a web application? Unless you are using something like
remoting or some other communications mechanism and the windows application
is already running... you are not going to be able to call a windows form
from a web application as you would be running into the same issue as trying
to launch Word on the client PC from the server.

Brendan
 

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