How to print a text file using C# [closed]


How can I print a text file in C#? In a console application.

This is what I've found: <a href="http://msdn.microsoft.com/en-us/library/aa287530%28v=vs.71%29.aspx" rel="nofollow">msdn sample</a> and this <a href="https://stackoverflow.com/questions/1472153/print-a-txt-to-the-default-printer-with-c-sharp" rel="nofollow">stackoverflow:answer is the msdn sample</a>

The code from the links are for windows forms applications, and does'nt work in an console appliction.

Here is what I've found:

string fileName = @"C:\data\stuff.txt"; ProcessStartInfo startInfo; startInfo = new ProcessStartInfo(fileName); if (File.Exists(fileName)) { int i = 0; foreach (String verb in startInfo.Verbs) { // Display the possible verbs. Console.WriteLine(" {0}. {1}", i.ToString(), verb); i++; } } startInfo.Verb = "print"; Process.Start(startInfo);

Since you say this question is off topic and not relevant here is a link to what I'm trying to learn: <a href="http://msdn.microsoft.com/library/vstudio/hh156542" rel="nofollow">This is documentation of the .Net framework</a> and this is why I'm asking the question, I'm trying to learn about the various uses of .Net classes.


You can use the PRINT verb to print a file to the default printer using the <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx" rel="nofollow">Process</a> and <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo%28v=vs.110%29.aspx" rel="nofollow">ProcessStartInfo</a> classes:

System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(@"C:\temp\output.txt"); psi.Verb = "PRINT"; Process.Start(psi);


  • PHP XPath. How to return string with html tags?
  • Selenium: find element by visible Text
  • How can I escape backslash in logstash grok pattern?
  • curl not working for getting a web page content, why?
  • Can long-polling be achieved in Restlet by just making the thread sleep?
  • Retaining data after updating application
  • how to upload multiple files in c# windows application
  • Groovy: Unexpected token “:”
  • GridView breaks while scrolling
  • How to suppress a dialog
  • copying resource to sdcard gives a damaged file in android
  • How to create a file in java without a extension
  • Database structure design with variable amounts of fields
  • How to install a .deb file on a jailbroken iphone programmatically?
  • Handling un-mapped Rest path
  • how to adjust image in a panel in Java swing?
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • Problems to linebreak with an int in JLabel
  • How reduce the height of an mschart by breaking up the y-axis
  • output of program is not same as passed argument
  • MySQL WHERE-condition in procedure ignored
  • Rearranging Cells in UITableView Bug & Saving Changes
  • AT Commands to Send SMS not working in Windows 8.1
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Comma separated Values
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • coudnt use logback because of log4j
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • embed rChart in Markdown
  • apache spark aggregate function using min value
  • Sorting a 2D array using the second column C++
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • reshape alternating columns in less time and using less memory
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app
  • java string with new operator and a literal
  • How to load view controller without button in storyboard?