Group: microsoft.public.word.vba.general
From: =?Utf-8?B?c2F0aXNo?=
Date: Wednesday, March 05, 2008 6:35 AM
Subject: Printing in C#.net

While printing in C#.net using ms word documents the printer properties like
colour and double side printer is unable to change through coding
For this we have to select the printer from the dialog box and select on it
by right click we can change the printer properties but I want with coding.
So please send if you any sujestion or code in c#.net.

> if (checkBox2.Checked == true)
> > {
> > object myTrue = true;
> > object myFalse = false;
> > object missingValue = Type.Missing;
> > object range =
> > Microsoft.Office.Interop.Word.WdPrintOutRange.wdPrintAllDocument;
> > object items =
> > Microsoft.Office.Interop.Word.WdPrintOutItem.wdPrintDocumentContent;
> > object copies = "1";
> > object pages = "10";
> > object pageType =
> > Microsoft.Office.Interop.Word.WdPrintOutPages.wdPrintAllPages;
> > try
> > {
> >
> >
> > int j = 0;
> >
> > for (; intClientId == 0 || j <
> > dsCompleteClient.Tables[2].Rows.Count; j++)
> > {
> >
> >
> > object oTemplate = arrDocuments[4];
> >
> > oDoc = oWord.Documents.Add(ref oTemplate, ref
> > missing, ref missing, ref missing);
> >
> > for (int i = 0;intClientId!=0 && i <
> > dsCompleteClient.Tables[2].Columns.Count; i++)
> > {
> >
> > oBookmarkName = "A" + (i + 1);
> >
> > wrdRng = oDoc.Bookmarks.get_Item(ref
> > oBookmarkName).Range;
> > if (i == 7)
> > {
> > decimal al;
> >
> > decimal.TryParse(dsCompleteClient.Tables[2].Rows[j][i].ToString(), out
> > al);
> > string st = string.Format("{0:c2}",
> > al);
> > wrdRng.InsertAfter(st);
> >
> > }
> > else
> > {
> >
> >
> > wrdRng.InsertAfter(dsCompleteClient.Tables[2].Rows[j][i].ToString());
> > }
> > }
> >
> > filename = arrDocuments[5];
> > if (j > 0)
> > {
> > filename =
> > filename.ToString().Replace("AnnuityInventoryWorksheet.doc", "Page" +
> > j.ToString() + ".doc");
> > }
> >
> > oDoc.SaveAs(ref filename, 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);
> >
> > if (intClientId == 0 ||
> > dsCompleteClient.Tables[2].Rows.Count <= 1)
> > {
> > if (bolPrinterSelect == true)
> > {
> > copies =
> > printDialog1.PrinterSettings.Copies.ToString();
> >
> > object prnName =
> > printDialog1.PrinterSettings.PrinterName.ToString();
> > oWord.ActivePrinter =
> > prnName.ToString();
> > object
> > Background=printDialog1.PrinterSettings.DefaultPageSettings.Color;
> >
> > //if
> > (printDialog1.PrinterSettings.Duplex.ToString() == "Simplex")
> > //{
> > oDoc.PrintOutOld(ref Background,
> > ref
> > myFalse, ref range,
> > ref missing, ref
> > missing,
> > ref missing,
> > ref items, ref
> > copies,
> > ref pages, ref pageType, ref myFalse,
> > ref myTrue, ref
> > missing,
> > ref myFalse);
> > //}
> > //else
> > //{
> > // oDoc.PrintOutOld(ref Background,
> > ref
> > myFalse, ref range,
> > // ref missing, ref
> > missing, ref missing,
> > // ref items, ref
> > copies,
> > ref pages, ref pageType, ref myFalse,
> > // ref myTrue, ref
> > missing, ref myTrue);
> > //}
> >
> > if (oWord.BackgroundPrintingStatus > 0)
> > {
> >
> > System.Threading.Thread.Sleep(1000);
> > }
> > }
> > if (intSavePrint == 1)
> > {
> > fileDocuments.Add(filename);
> > }
> > }
> > oDoc.Close(ref missing, ref missing, ref
> > missing);
> >
> > System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc);
> > oDoc = null;
> > if (intClientId == 0)
> > {
> > break;
> > }
> >
> > }
> > if (j > 1)
> > {
> > object oTemplate = arrDocuments[5];
> > filename = arrDocuments[5];
> > oDoc = oWord.Documents.Add(ref oTemplate, ref
> > missing, ref missing, ref missing);
> > Word.Selection selection1 = oWord.Selection;
> > try
> > {
> > DirectoryInfo dir = new
> > DirectoryInfo(strcopyTemplate);
> > FileInfo[] fn = dir.GetFiles("Page*.doc");
> > for (int i = 0; i < fn.Length; i++)
> > {
> > if
> > (File.Exists(fn[i].FullName.ToString()))
> > {
> >
> > selection1.InsertFile(fn[i].FullName.ToString(), ref missing, ref
> > missing,
> > ref missing, ref missing);
> > selection1.InsertBreak(ref
> > pageBreak);
> > fn[i].Delete();
> > }
> > }
> > oDoc.SaveAs(ref filename, 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);
> > }
> > catch
> > {
> > oDoc.SaveAs(ref filename, 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);
> > }
> > if (bolPrinterSelect == true)
> > {
> > copies =
> > printDialog1.PrinterSettings.Copies.ToString();
> > object prnName =
> > printDialog1.PrinterSettings.PrinterName.ToString();
> > oWord.ActivePrinter = prnName.ToString();
> >
> > printDialog1.PrinterSettings.DefaultPageSettings.Color = true;
> > object Background =
> > printDialog1.PrinterSettings.DefaultPageSettings.Color;
> >
> > //printDialog1.PrinterSettings.DefaultPageSettings.Color = true;
> > //if
> > (printDialog1.PrinterSettings.Duplex.ToString() == "Simplex")
> > //{
> > oDoc.PrintOutOld(ref Background, ref
> > myFalse, ref range,
> > ref missing, ref
> > missing, ref
> > missing,
> > ref items, ref copies,
> > ref
> > pages, ref pageType, ref myFalse,
> > ref myTrue, ref missing,
> > ref
> > myFalse);
> > //}
> > //else
> > //{
> > // oDoc.PrintOutOld(ref Background, ref
> > myFalse, ref range,
> > // ref missing, ref
> > missing,
> > ref missing,
> > // ref items, ref copies,
> > ref
> > pages, ref pageType, ref myFalse,
> > // ref myTrue, ref
> > missing,
> > ref myTrue);
> > //}
> > if (oWord.BackgroundPrintingStatus > 0)
> > {
> > System.Threading.Thread.Sleep(1000);
> > }
> > }
> >
> >
> > oDoc.Close(ref missing, ref missing, ref
> > missing);
> >
> > System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc);
> > oDoc = null;
> > if (intSavePrint == 1)
> > {
> > fileDocuments.Add(filename);
> > }
> > }
> >
> >
> > }
> > catch (Exception ex)
> > {
> >
> > CommonModule.proc_ErrorMessage(ex.Message.ToString() +
> > "Error in Annuity data");
> > }
> > }
> >