I'm having a really weird problem with Interop.
I developed a small program that opens a Microsoft.Office.Interop.Word.Application and use it to prints documents:
object[] oWordDialogParams = { printerName, true };
string[] argNames = { "Printer", "DoNotSetAsSysDefault" };
object wordBasic = wordApplication.WordBasic;
try
{
wordBasic.GetType().InvokeMember("FilePrintSetup"
, BindingFlags.InvokeMethod
, null
, wordBasic
, oWordDialogParams
, null
, null
, argNames);
}
catch (Exception e)
{
Logger.Instance.Log("failed to set printer");
}
doc.Activate();
wordApplication.PrintOut(Background: ref backgroundPrint, FileName: ref sourceFile);
Everything works fine pretty always (I would say 95% of the times), I'm able to see the correct print queue and, most important, the printer settings are the default printer settings (i.e.: nothing happens in the printer preferences):
But, in a few cases, the document is passed to the printer without the extension (docx in this case) and the printer setting are changed (for example the paper size is set to letter):
Please note that:
in my code the FileName: ref sourceFile is always correctly set with the extension, but (randomly!) it appears in the print queue without the extension. When this happens it means also that the printer settings are changed to something not default.
the exact same document reprinted works fine (!)
I'm working with:
- framework 4.0
- interop 12.0
- windows server 2008 R2
- the printer uses the HP Universal Print Driver
Thank you all for your precious help!