Search code examples
c#printingms-wordconsolemailmerge

C# 4.0 Console Word MailMerge print error


I have an automated MailMerge app that gets data from a SQL database and merges with a Word .dotx then prints.

The mailmerge works fine. When it gets to the print it Opens Word, says there was a print error. But when you click OK, word closes and it prints just fine.

Not sure what the error would be, but the fact I have to click OK would hinder an automated process.

Here is my print code

//PRINT
System.Diagnostics.Process print = new System.Diagnostics.Process();
print.StartInfo.FileName = outputFilename;
print.StartInfo.Verb = "PrintTo";
print.StartInfo.CreateNoWindow = true;
//DEV
var printerName = @"\\cdssvprn03\9858sam77501";
print.StartInfo.Arguments = printerName;
print.StartInfo.UseShellExecute = true;
print.Start();
print.WaitForExit();

Any ideas on where to start?


Solution

  • I found an alternate method for background printing...

    //PRINT LETTER
    Console.WriteLine("Printing: " + outputFilename);
    string filename = outputFilename;
    Application app = new Application();
    //DEV/TEST
    var printerName = @"\\CDSSVPRN03\9858sam77501";  
    app.ActivePrinter = printerName;  
    app.Documents.Open(filename);
    app.PrintOut();