Reputation: 733
How do I print a .txt file in vb.net? Hopefully without using any third parties.
Upvotes: 2
Views: 29898
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
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