How can i print a text file in c#?
I've been looking on the internet and found code, but I just need it on paper, don't care what type of letters, just a regular print..
And i want to keep the code short.
I've found long code, but I've got to make it work at thuesday 25/05..
I tried:
PrintDocument pd = new PrintDocument();
pd.DocumentName = ("c:\\GIP_Foto\\data.log");
pd.Print();
But it just opens a new screen to select what you want to print..
need help?

that's the one I found to, but it's pretty long..
+ I only understand half of his code

Post what you don't understand...

when i already know where the file is, how do i replace the first button?
I know the printing part, but I don't understand a lot of the PrintTextFileHandler..

But replacing the path should give me:

//Create a StreamReader object
reader = new StreamReader (c:\\gip_foto\\data.log);
//Create a Verdana font with size 10
verdana10Font = new Font ("Verdana", 10);
//Create a PrintDocument object
PrintDocument pd = new PrintDocument();
//Add PrintPage event handler
pd.PrintPage += new PrintPageEventHandler(this.PrintTextFileHandler);
//Call Print Method
pd.Print();
//Close the reader
if (reader != null)
reader.Close();

Problem solved, I copied code, but when I cancel the print (after clicking print), there's a fault, but i just catch it with an exception message..
Thanks anyway!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.