How to print a txt file

InDistress

Member
Joined
Mar 10, 2007
Messages
14
Programming Experience
Beginner
Howdy all,

Can anyone help me with some code that will print a txt file without any dialogue boxes?

The file path is C:\test.txt

I've scoured google and can't quite find what I'm looking for.


Thanks in advance
InDistress
 
Here is a plain text printing class 'TextPrint' by Karl Moore http://www.developer.com/net/net/article.php/3102381
It could be used as follows:
VB.NET:
Dim tp As New TextPrint(My.Computer.FileSystem.ReadAllText("test.txt"))
tp.Print()
You can also call the OS to print the file with default application (usually Notepad for .txt files):
VB.NET:
Dim p As New Process
Dim info As New ProcessStartInfo
info.FileName = "test.txt"
info.Verb = "print"
p.StartInfo = info
p.Start()
 
Cheers for that JohnH - it worked a treat. As a off spin question, is there any way that I can prevent the screen from displaying the textfile before it prints? Whenever ever I hit the print button, it brings the text file into view for a brief second and then disappears - I guess I just want it to look seemless to the user.


Cheers
InDistress
 
You would have to use the first option, it's printing with the .Net PrintDocument class.
 
Hi John,

I tried your first print option that you mentioned and it didn't seem to pickup the 'TextPrint' portion of the code. It tells me that the Type 'TextPrint' is not defined.

Here's what I've been using

Dim tp As New TextPrint(My.Computer.FileSystem.ReadAllText("C:\test.txt"))

Any suggestions?
 
You have copy the TextPrint class (="type") I linked to and add to your project.
 
Back
Top