SoFunction
Updated on 2025-03-01

c# Get the installed printer and call the print file

C# gets all installed printer codes as follows:

using ;
 var printers = ;
 foreach (var item in printers)
 {
   (());
 }

C# calls the printer to print files. Generally, for example, Word, Excel, PDF, etc. can be printed using some corresponding components. Another common way is to directly enable a printing process for printing. The sample code is as follows:

using ;

string filePath = "File Path";
string printer = "printer";
ProcessStartInfo info = new ProcessStartInfo();
 = "\"" + printer + "\"";
 = "PrintTo";
 = filePath;
 = true;
 = ;
 
Process p = new Process();
 = info;
();
();

In addition, PrintTo may not be supported in a production environment. To determine which commands are available for a file under a specific system, the following code needs to be executed under a specific system. The following code is to determine the commands supported by a file under a specific system:

using ;

string filePath = "File Path";
ProcessStartInfo info = new ProcessStartInfo();
 = filePath;
foreach(var verb in )
{
  (verb);
}

The above is the detailed content of C# obtaining installed printers and calling print files. For more information about C# printing files, please pay attention to my other related articles!