user154966
user154966

Reputation:

Creating and saving word doc on server

i have this web application in c# .net running on an external web server.In that i am trying to generate and save the word doc on the server ( without opening it) . It runs fines on my local machine as i am having word installed on my machine but on the server it is showing error on using MyApplication Class. I understand it is not possible to install word on the server . Right now i am referenceing word.interopp assembly in my application . Is there any better way to solve the issue .

Thanks and regards

Vickey Y.

Upvotes: 3

Views: 2744

Answers (7)

Gineer
Gineer

Reputation: 2408

Take a look at OpenXML which is the file format all word (and Office) documents are saved in by default. http://openxmldeveloper.org/

Upvotes: 0

Liquid
Liquid

Reputation: 1871

I think you can do something like this. I should alow you to open a document from the server.

protected void btnCreateWordBulletin_Click(object sender, EventArgs e)
{
String a= Server.MapPath("/Solution/Templates/Sport/Sport.doc"); 
String b= Server.MapPath("/Solution/Templates/Sport/SportSave.doc"); 
CreateWordDocument(a, b); 
}

protected void CreateWordDocument(object fileName, object saveAs)
{
    //Set Missing Value parameter - used to represent
    //a missing value when calling methods through interop
    object missing = System.Reflection.Missing.Value;
//Setup the Word.App class
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document aDoc = null;
// Check to see that file exists
if (System.IO.File.Exists((string)fileName))
{... Activating doc etc...}}

Upvotes: 2

Eisbaer
Eisbaer

Reputation: 199

OfficeWriter is another potential solution for you if you need true DOC and DOCX (as opposed to RTF or some other format):

http://www.officewriter.com

Upvotes: 0

smok1
smok1

Reputation: 2950

Yes, you can have Word running on server. However, note that opening winword.exe process from web service will probably fire winword.exe as ASPNET user. Some versions of MS word displayed some customization modal form during first run, making it impossible to automate process of using Word in server environment. The solution was making ASPNET “login-enabled” user, logging to server as an ASPNET user, running Word manually, closing all first-time-configuration modal forms, and then setting ASPNET user to its normal state. Since those configuration windows appeared only during first run of winword (more precisely: until configuration was approved by user), this actually worked.

Note: using winword on server needs some legal investigation. As far as I know MS attitude towards such solutions is rather negative, while some legal systems find it perfectly ok. Also take into consideration need for managing winword processes, and … and in fact, this is a bit crude hack.

Upvotes: 1

Robin Day
Robin Day

Reputation: 102468

We use a third party tool called Aspose.Word. This allows you to perform a whole bunch of Word releated stuff without the need to install Word itself on the server.

Upvotes: 3

Jon Skeet
Jon Skeet

Reputation: 1499880

If you're trying to use Office Interop without installing office on the server, then it's clearly going to fail.

Could you install Word on a different server and expose some sort of web service to create the document for you and serve the file contents back to the original server to save?

You may be able to use some third party libraries which can generate the relevant Word format, but I don't know of any.

What format does it have to be? Is it a complicated document? Could you just use RTF?

Upvotes: 3

Russell
Russell

Reputation: 17719

the word.interop uses an instance of word to generate and save the documents. Even though it doesnt display the UI, the process of WINWORD will be running. In short, you need word installed on the server to use word.interop. When we did this, we also encountered issues when the servers needed to be compatible with word 2007 documents too, so its not an easy venture working with Word. Hope you get through the issue ok :)

Upvotes: 2

Related Questions