?
Solved

Server execution failed - Word(2000-2003) Automation ASP.NET/C#

Posted on 2004-04-16
5
Medium Priority
?
1,584 Views
Last Modified: 2008-02-25
This is close to what I'm looking for.: http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20716375.html but I'm using Word.
I'm trying to automate Word on a server (that has Word 2000) using ASP.NET to background print to the server's default printer. It works fine locally on my development machine printing to my default/network printer.
The server has Word 2000 and I have 2003. I'm using MSWORD9.OLB after using references to PIA's ver.11 and 10 to no avail.
Here's the code: (minus error trapping)

My error occurs with an error message of ('Server execution failed') on the following line:
        oWordApp = new Word.ApplicationClass();

        object fileName = Server.MapPath(@"/CFMSystem/test.doc");

          // Open Existing Word Document
          oWordDoc = oWordApp.Documents.Open(
            ref fileName, ref missing, ref readOnly,
            ref missing, ref missing, ref missing,
            ref missing, ref missing, ref missing,
            ref missing, ref missing, ref isVisible,
            ref missing, ref missing, ref missing, ref missing);

          oWordDoc.Activate();

          // Write to Document
          oWordApp.Selection.WholeStory();
          oWordApp.Selection.Text = "Printing info for xyz";

          // Save Document
          oWordDoc.Save();

          oWordApp.PrintOut(
            ref isTrue, ref missing, ref missing,
            ref missing, ref missing, ref missing,
            ref missing, ref missing, ref missing,
            ref missing, ref missing, ref missing,
            ref missing, ref missing, ref missing,
            ref missing, ref missing, ref missing, ref missing);

        //  Monitor Background Printing Status before closing
        Response.Write("Printing ");
        while (oWordApp.BackgroundPrintingStatus != 0) {
          Response.Write(". ");
        }
        Response.Write("Done");
       
        // Close Document
        oWordDoc.Close(ref missing, ref missing, ref missing);
       
        // Quit Application
        oWordApp.Application.Quit(ref missing, ref missing, ref missing);
0
Comment
Question by:famoso
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 

Author Comment

by:famoso
ID: 10858968
That isn't working for me - Plus I'm using ASP.NET.  Anyone have any other suggestions?
0
 

Author Comment

by:famoso
ID: 11099176
Admin can close this.  Word shouldn't be automated from ASP.NET.  My suggested solution is to create a Windows form with a browser control to reference the web app and use a windows form button to print the 'document' from the client after processing on the webserver is finished.  Try referencing ie: \\server\c$\inetpub\wwwroot\etc\someworddoc.doc and print to the default printer... Any questions, email me clonedaddress-expertsexchange@yahoo.com.

Here's my code to print a file (.doc) [i got this code from somewhere and altered it a bit]

using System;
using System.Diagnostics;
using System.ComponentModel;

namespace GeneralProcesses {
  /// <summary>
  /// Shell for the sample.
  /// </summary>
  public class GPPrint {
    // These are the Win32 error code for file not found or access denied.
    const int ERROR_FILE_NOT_FOUND = 2;
    const int ERROR_ACCESS_DENIED  = 5;

    /// <summary>
    /// Prints a file with a .doc extension.
    /// </summary>
    public void Print_doc(string filename) {
      Process myProcess = new Process();

      try {
        // Get the path that stores user documents.
        myProcess.StartInfo.FileName = filename.ToString();

        // Set the verb to use when opening the document
        myProcess.StartInfo.Verb = "Print";

        // Start the process in new window
        myProcess.StartInfo.CreateNoWindow = true;

        // Start the process
        myProcess.Start();

        // Wait for the process to exit
        myProcess.WaitForExit(90);

        if (myProcess.ProcessName!="") {
          myProcess.Kill();
        }
      }
      catch (Win32Exception e) {
        if(e.NativeErrorCode == ERROR_FILE_NOT_FOUND) {
          Console.WriteLine(e.Message + ". Check the path.");
        }

        else if (e.NativeErrorCode == ERROR_ACCESS_DENIED) {
          // Note that if your word processor might generate exceptions
          // such as this, which are handled first.
          Console.WriteLine(e.Message + ". You do not have permission to print this file.");
        }
      }
      catch (Exception) {
        return;
      }
    }

  }
}
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 11300186
PAQed, with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question