Set a print job's document name in C#

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'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 document name you entered.


Comments