Lucas_Santos
Lucas_Santos

Reputation: 4740

Word Interop Issue with ASP.NET

About Microsoft.Office.Interop.Word.

I installed the PIA and Microsoft Office 2010 in my web server, but I can't generate a .doc when I run the application published in my web server. When I run my application in localhost, works fine, and generate the .doc file.

I have to do some configuration in server side to allow the generation of .doc files ?

Upvotes: 0

Views: 2419

Answers (3)

Yahia
Yahia

Reputation: 70369

Office Interop is NOT supported by MS in "server-like scenarios" (which IIS/ASP.NET is a special kind of)... see http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2

Your options include several libtraries (free and commercial) - for example:

Regarding the exception you get:

Since Windows Vista several changes have been introduced to stop any Windows Service (IIS is just some special one) from doing anything "desktop-like" - this is due to security issues... to resolve such a situation you would need to circumvent those security measures implemented by MS - which I absolutely do NOT recommend...

Upvotes: 0

James Johnson
James Johnson

Reputation: 46047

You should be using the Open XML SDK for this. The office interops are outdated relics, and should not be used.

Download link:
http://www.microsoft.com/download/en/details.aspx?id=5124

Here's a simple example of how to create a Word document:

public void HelloWorld(string docName) 
{
  // Create a Wordprocessing document. 
  using (WordprocessingDocument package = WordprocessingDocument.Create(docName, WordprocessingDocumentType.Document)) 
  {
    // Add a new main document part. 
    package.AddMainDocumentPart(); 

    // Create the Document DOM. 
    package.MainDocumentPart.Document = 
      new Document( 
        new Body( 
          new Paragraph( 
            new Run( 
              new Text("Hello World!"))))); 

    // Save changes to the main document part. 
    package.MainDocumentPart.Document.Save(); 
  } 
}

See this MSDN article for more details:
http://msdn.microsoft.com/en-us/library/dd440953%28v=office.12%29.aspx

Upvotes: 0

Philipp Schmid
Philipp Schmid

Reputation: 5828

Remember that Office 2010 was not designed to run inside a web server (e.g., thread safety might not be guaranteed), so you might encounter more difficulties down the line.

Instead, consider using the Open SDK 2.0 from Microsoft, which allows you to manipulate (create, edit) Office 2010 documents, which are simply packaged (zipped) XML files. This technology is much better suited for server use. It also doesn't require you to have a separate Office 2010 license for each web server where you are going to install Office 2010.

Upvotes: 3

Related Questions