Connor Albright
Connor Albright

Reputation: 733

How do I print a text file in .net

How do I print a .txt file in vb.net? Hopefully without using any third parties.

Upvotes: 2

Views: 29898

Answers (2)

Tim Schmelter
Tim Schmelter

Reputation: 460108

Have a look at this example on how to print files with VB.Net: MSDN How to: Print a Multi-Page Text File in Windows Forms

The most important class you need is PrintDocument. No third party tools or Dll's other than in System.Drawing and System.IO Namespace in .Net-Framework(> 1.1) are needed.

Upvotes: 3

Justin Grant
Justin Grant

Reputation: 46683

See How to print batch file in vb.net?. There's a VB.NET code sample which you should be able to use verbatim.

If you don't already know how to pull text out of a file, use File.ReadAllText, like this:

Imports System.IO
Dim path As String = "c:\temp\MyTest.txt"
RawPrinterHelper.SendStringToPrinter("WindowsPrinterName", File.ReadAllText(path)) 

RawPrinterHelper is the class described in the other question linked above. "WindowsPrinterName" is the name of the printer you want to print to.

Upvotes: 4

Related Questions