Hi All - I've been struggling with this problem for some time and a friend recommended I try the guys here to see if they can help. I apologize if this is in the wrong forum.
I have a large desktop application. Part of it takes Word templates, populates data, and then prints them. This seems to work fine on XP, but we have been facing problems with Vista.
I've isolated the problem to the point where it seems Vista won't even print the template before it's populated. My method will print other, more simple documents, in Vista.
Here is the snippet of code we are using. The document gets sent to the Print Spool, but then nothing happens. It just sits there and says Printing (in the program below, it gets stuck in an infinite loop on while (wordApp.Application.BackgroundPrintingStatus > 0)
If I happen to open Word while it's stuck, it will print. If I set the printing background parameter to False, it also prints but then I get a message that says Word has stopped working. If I open the document in Word manually and go to File->Print, it prints fine. I've tried both PrintOutOld and PrintOut2000 with the same results. Unfortunately, I don't have any other machines with Vista on it so it's tough to test to see if this is a localized problem or more widespread. As mentioned above, this will print simpler documents fine. But of course, our application doesn't have simple documents.
Here is a link to the document I am trying to print:
http://www.SimDynasty.com/docs/test21.doc
--------------------
Word._Application wordApp = new Word.Application();
object myTrue = true;
object oFaxFile = textBox1.Text;
object readOnly = false;
object missingValue = System.Type.Missing;
Microsoft.Office.Interop.Word._Document doc = wordApp.Documents.Open(ref oFaxFile,
ref myTrue, ref missingValue, ref missingValue,
ref missingValue, ref missingValue, ref missingValue,
ref missingValue, ref missingValue, ref missingValue,
ref missingValue, ref missingValue, ref missingValue,
ref missingValue, ref missingValue, ref missingValue);
object range = Microsoft.Office.Interop.Word.WdPrintOutRange.wdPrintAllDocument;
object items = Microsoft.Office.Interop.Word.WdPrintOutItem.wdPrintDocumentContent;
object copies = "1";
object pages = "10";
object myFalse = false;
object pageType = Microsoft.Office.Interop.Word.WdPrintOutPages.wdPrintAllPages;
doc.PrintOut(ref myTrue, ref myFalse, ref range,
ref missingValue, ref missingValue, ref missingValue,
ref items, ref copies, ref missingValue, ref pageType, ref myFalse,
ref myTrue, ref missingValue, ref myFalse, ref missingValue, ref missingValue, ref missingValue, ref missingValue);
int ctr = 0;
while (wordApp.Application.BackgroundPrintingStatus > 0)
{
System.Threading.Thread.Sleep(500);
ctr = ctr + 1;
}
MessageBox.Show(ctr.ToString());
doc.Close(ref missingValue, ref missingValue, ref missingValue);
wordApp.Quit(ref missingValue, ref missingValue, ref missingValue);
-----------------
Any suggestions on troubleshooting or possible solutions would be greatly appreciated.
Thanks!
Tyson