How to Select my Printer when using .PrintOut [C#]

Shaitan00

Junior Contributor
Joined
Aug 11, 2003
Messages
358
Location
Hell
Specifically - I am trying to send a .DOC file to a FAX using C#.NET Office Automation (COM Microsoft Word 11.0 Object Library), so far I have the following:

Code:
Word.ApplicationClass wordApp = null;
private bool SendFax()
{
	object missingValue = Type.Missing; 
	object myTrue = true;
	object oFaxFile = sFaxFile;

	wordApp = new Word.ApplicationClass();
	Word.Document doc = wordApp.Documents.Open(ref oFaxFile,
		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, ref missingValue);

	FaxOutDoc(doc);

	doc.Close(ref missingValue, ref missingValue, ref missingValue);
	return true;
}

private bool FaxOutDoc(Word.Document doc)
{
	object myTrue = true; 
	object myFalse = false; 
	object missingValue = Type.Missing; 
	object range = Word.WdPrintOutRange.wdPrintCurrentPage; 
	object items = Word.WdPrintOutItem.wdPrintDocumentContent; 
	object copies = "1"; 
	object pages = "1"; 
	object pageType = Word.WdPrintOutPages.wdPrintAllPages; 

	doc.PrintOut(ref myTrue, ref myFalse, ref range, 
		ref missingValue, ref missingValue, ref missingValue, 
		ref items, ref copies, ref pages, ref pageType, ref myFalse,
		ref myTrue, ref missingValue,  ref myFalse, ref missingValue, 
		ref missingValue, ref missingValue, ref missingValue); 

	return true;
}

My problem is pretty simple - when I run this code I am unable to select which PRINTER I want to print to, it seems to automatically send it to the default Printer defined in Windows.
So, what I need to do is:
a) Select the FAX PRINTER (as opposed to the default printer), I don't force the user to change defaults when using this application
b) Define the Fax Properties (such as Phone Number, etc...) so the user isn't prompted to fill it in

Is there anyway to automate this in C#.NET Office Automation using the COM object?
Thanks,
 
Hi
You don't actually need to specify the printer in the PrintOut command, instead you can set it at the Word Application level:
Code:
wordApp = new Word.ApplicationClass();
WordApp.ActivePrinter = YourFaxPrinter

If you want to specify the Tray you would use:
Code:
wordApp = new Word.ApplicationClass();
wordApp.ActivePrinter = "YourFaxPrinter"

Word.Document doc = wordApp.Documents.Open(ref oFaxFile,
		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, ref missingValue);
doc.PageSetup.FirstPageTray = "TrayName"
Not sure how to specify the other fax properties though.
 
Last edited:
Back
Top