Microsoft KB Archive/820644

= &quot;PrintDocument Class&quot; does not implement the PrintToFile feature =

Article ID: 820644

Article Last Modified on 5/18/2007

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual C# 2005 Express Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft .NET Framework 2.0
 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0

-





SUMMARY
In the Microsoft .NET Framework Class Library documentation, the help topic for PrinterSettings.PrintToFile Property, under the Remarks section, states the following:

Note This property is only used by the PrintDialog class and cannot be set programmatically.

However, when you try to set the PrintToFile property programmatically, you do not receive any error. Additionally, when you set the PrintToFile property to True, the PrintDocument class sends the output to a printer and not to a file.



MORE INFORMATION
The .NET Framework Class Library includes the PrinterSettings class. You can specify how a document is printed with the PrinterSettings class. You can access PrinterSettings through the PrintDocument.PrinterSettings property. When you set the PrintToFile property of the PrinterSettings class to True, it indicates that the data is printed to a file.

However, when you set the PrintToFile property to True by creating an instance of the PrintDocument class, the data is not printed to a file. This behavior occurs because the path of the destination file cannot be set by using the PrintDocument class.

Therefore, use the PrintDialog class. PrintDialog provides the required implementation to print the data to a file. When you create an instance of the PrintDialog class and then set the PrintDialog.AllowPrintToFile to True, the Print to file option is enabled on the Print dialog box when it appears. When you select the Print to file option, you are prompted for a file name. The data is then printed to the destination file that you specify as the output file name.

For more information, visit the PrintDialog Class Web site that is mentioned in the &quot;References&quot; section of this article.

