Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-04-16
5
Medium Priority
?
1,585 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

610 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