[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Set a print job name in C#

[Set a print job name in C#]

By default, when you send a PrintDocument to a printer, the printer spool shows the job's name as "document." You can change the print job name by setting the PrintDocument object's DocumentName property.

This example uses the following code to print a small sample document.

// Print the document. private void btnPrint_Click(object sender, EventArgs e) { // Select the printer. pdocFile.PrinterSettings.PrinterName = cboPrinter.Text; // Set the print document name. pdocFile.DocumentName = txtDocumentName.Text; // Print. pdocFile.Print(); }

The code sets the PrintDocument object's PrinterSettings.PrinterName property so output goes to the printer you selected from the ComboBox at the top of the form.

It then sets the DocumentName property to the value you entered in the TextBox.

Finally the code calls the PrintDocument object's Print method to start printing.

If you click the Print button and then check the selected printer's spool (before the document has finished printing), you should see the print job name that you entered.

Download the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.