0

Hi iam creating a Word document like:

    Dim oApp As Word.Application
    Dim oDoc As Word.Document

    oApp = CreateObject("Word.Application")


    oDoc = oApp.Documents.Add


    Dim rng As Word.Range = oDoc.Range(0, 0)
    rng.Font.Name = "Verdana"
    rng.Font.Size = 16


    .......
    ...............



    oApp.Visible = True

    oDoc = Nothing
    oApp = Nothing

This works perfect on my local machine. But if i put my Code on Webserver it of course does not work.

My Question is: What i have to do, that the Word document gets created on the server and offer the created document to the client as Download.

Can someone help me with that? Thanks!!

Paks
  • 1,460
  • 6
  • 26
  • 46

2 Answers2

0

I think they way you are currently doing this requires Microsoft Word (Or at least the Interop components) to be present on the server to allow this.

Perhaps a better approach would be to create a PDF on the fly and offer that to the client

alternatively perhaps this approach would work or this?

EDIT:

Also please see how-to-generate-word-documentdoc-docx-in-asp-net

EDIT:

This code snippet will allow you to stream the file down to the client

using (MemoryStream mem = new MemoryStream())
        {
            // Create Document
            using (<declare document>))
            {
               //create your document here


                // Stream it down to the browser

            Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
            Response.AppendHeader("Content-Disposition", "attachment;filename=HelloWorld.docx");
            mem.Position = 0;
            mem.CopyTo(Response.OutputStream);
            Response.Flush();
            Response.End();
            }

        }
Community
  • 1
  • 1
Dean
  • 5,896
  • 12
  • 58
  • 95
  • I have Microsoft word on my Webserver. It should be a Word document. Do you have a example on how to do that with vb.net? – Paks Dec 18 '12 at 07:01
  • How are you currently trying to stream the content down to the client? – Dean Dec 18 '12 at 07:03
-1

Just saw this...

I have managed to get Word running on a server (Apache). You must run Apache under a user account that can run Word. Also if you use Office 32-bit you must run Apache 32-bit. Only one instance of Word runs at one time. However, Word can have multiple documents open at the same time. I developed an addin that I put in Word's startup directory so it is available for each document. In the AutoExec macro I trigger the code that reads a job queue and generates the document. All this is run from the web using AJAX and PHP.

user2970483
  • 323
  • 5
  • 14