Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2007

Tip: Looking for answers? Try searching our database.

C# Printout method

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Virgul - 12 Jan 2007 10:46 GMT
Hi,

I try in my winform to open a word document print it and close.

But I have some problem when the document is to big word dont print it.

I think it's because I close it before that he have the time to complete
open it and launch the command to print.

I have put Thread.Sleep(5000); for wait a moment and that work!

But I dont to make wait my programm if they dont need to wait and if I have
a larger document that will not work so my question is what I need to make
for that my word document is print before close it?

My Code:

Word.Application newApp = new Word.Application();
Word.Document newdoc;
private void printWord(string ctp, string Temp)
{
newApp = new Word.Application();
string filePath = temp + "\\form" + cpt + ".pnet";

object o = System.Reflection.Missing.Value;
object True = true;
object Source = filePath;
newApp.Visible = false;
                   
newdoc = newApp.Documents.Open(ref Source, ref o, ref o, ref o, ref o, ref
o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o);
           
newdoc.PrintOut(ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref
o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o);
           
Thread.Sleep(5000);

if (SaveEhra == "1")
{
    object Source2 = temp + "\\EHRA.xml";
               
    newdoc.XMLSaveDataOnly = true;
    newdoc.SaveAs(ref Source2, ref o, ref o, ref o, ref o, ref o, ref o,
ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o);
}

newdoc.Close(ref o, ref o, ref o);
object Savequit = false;

newApp.Quit(ref Savequit, ref o, ref o);
}

Have you any idea about what I'm doing wrong?

Thanks a lot for your help

++

Thierry
Jay Freedman - 12 Jan 2007 14:58 GMT
The first parameter of the PrintOut method is Background, which controls
whether Word uses a background thread to send the document to the
printer/spooler. The default value of the parameter is True, which allows
the program to continue while the document prints. That's why the document
closes before printing is complete.

You need to send the value False, which forces Word to print in the
foreground thread and not continue your code until printing is complete.
With that in place, you can remove the Sleep call.

Signature

Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

> Hi,
>
[quoted text clipped - 58 lines]
>
> Thierry
Virgul - 15 Jan 2007 07:52 GMT
Thanks Jay!

I have read all other properties execpt this one beacuase I was thinking
that is for for print background picture...

++

Thierry

> The first parameter of the PrintOut method is Background, which controls
> whether Word uses a background thread to send the document to the
[quoted text clipped - 68 lines]
> >
> > Thierry
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.