473,385 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to Print PRN file

Any information on the best way to print a prn file from within a VB.Net Web
Application would be appreciated.
Thanks,
Michael Murphy
954-452-1047
md******@scs-techresources.com
Nov 21 '05 #1
13 8450
"Michael D Murphy" <md******@scs-techresources.com> schrieb:
Any information on the best way to print a prn file from within a VB.Net
Web Application would be appreciated.


Where should the file be printed? On the server? On the client?

Untested:

HOW TO: Send Raw Data to a Printer by Using Visual Basic .NET
<URL:http://support.microsoft.com/?scid=kb;EN-US;322090>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2
Thanks for the reply.
I need to print the prn file on the server.
Michael

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Ob**************@TK2MSFTNGP14.phx.gbl...
"Michael D Murphy" <md******@scs-techresources.com> schrieb:
Any information on the best way to print a prn file from within a VB.Net
Web Application would be appreciated.


Where should the file be printed? On the server? On the client?

Untested:

HOW TO: Send Raw Data to a Printer by Using Visual Basic .NET
<URL:http://support.microsoft.com/?scid=kb;EN-US;322090>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3
Hi

Based on my test, the code in the KB will work for ASP.NET application.
http://support.microsoft.com/?scid=kb;EN-US;322090

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If RawPrinterHelper.SendFileToPrinter("PrinterName", "C:\test.prn")
Then
Response.Write("OK")
Else
Response.Write("Failed")
End If
End Sub

In this way the test.prn is located on the IIS Server.
In addition we need to configure the ASP.NET process to run under the user
account which has added the "PrinterName" printer.

If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #4
Peter,
Thanks for your help!
That should do it.
Michael

""Peter Huang" [MSFT]" <v-******@online.microsoft.com> wrote in message
news:7L**************@TK2MSFTNGXA03.phx.gbl...
Hi

Based on my test, the code in the KB will work for ASP.NET application.
http://support.microsoft.com/?scid=kb;EN-US;322090

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If RawPrinterHelper.SendFileToPrinter("PrinterName", "C:\test.prn")
Then
Response.Write("OK")
Else
Response.Write("Failed")
End If
End Sub

In this way the test.prn is located on the IIS Server.
In addition we need to configure the ASP.NET process to run under the user
account which has added the "PrinterName" printer.

If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 21 '05 #5
Peter,
If I wanted to spawn the printing of the PRN file as a new thread, what
would I have to do differently??
Michael
"Michael D Murphy" <md******@scs-techresources.com> wrote in message
news:uc*************@TK2MSFTNGP14.phx.gbl...
Peter,
Thanks for your help!
That should do it.
Michael

""Peter Huang" [MSFT]" <v-******@online.microsoft.com> wrote in message
news:7L**************@TK2MSFTNGXA03.phx.gbl...
Hi

Based on my test, the code in the KB will work for ASP.NET application.
http://support.microsoft.com/?scid=kb;EN-US;322090

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If RawPrinterHelper.SendFileToPrinter("PrinterName",
"C:\test.prn")
Then
Response.Write("OK")
Else
Response.Write("Failed")
End If
End Sub

In this way the test.prn is located on the IIS Server.
In addition we need to configure the ASP.NET process to run under the
user
account which has added the "PrinterName" printer.

If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.


Nov 21 '05 #6
Hi

We do not need to do special things, we just need to create a new thread to
run the print code.
e.g.
Private Sub Print()
If RawPrinterHelper.SendFileToPrinter("printername", "C:\test.prn")
Then
Response.Write("OK")
Else
Response.Write("Failed")
End If
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim th As New Threading.Thread(AddressOf Print)
th.Start()
th.Join()
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #7
Hi Peter,
Thanks for responding.
Just so I understand it correctly, I just have to spawn the print thread one
time in the form load and then every time I call the print function it will
automatically be executed in a new thread? This is my situation. I have an
XP Embedded program that runs mpeg files on the media player. I want the
player to keep playing, but if the user clicks the right mouse button, I
want to print a prn file associated with what the user is watching. Based on
what I have told you, can I still declare the new thread only once, or do I
need to declare it every time I need to print?
Thanks,
Michael

""Peter Huang" [MSFT]" <v-******@online.microsoft.com> wrote in message
news:qW**************@TK2MSFTNGXA03.phx.gbl...
Hi

We do not need to do special things, we just need to create a new thread
to
run the print code.
e.g.
Private Sub Print()
If RawPrinterHelper.SendFileToPrinter("printername", "C:\test.prn")
Then
Response.Write("OK")
Else
Response.Write("Failed")
End If
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim th As New Threading.Thread(AddressOf Print)
th.Start()
th.Join()
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 21 '05 #8
Hi

If we spawn a new thread to run certain method, once the method exited, the
thread will exit too.
So one approach is run the thread on a method which have a while statement,
and the while statement will keep querying for a file or certain var to do
the print.
Otherwise, we need to spawn a new thread every time to run the print method.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #9
Hi Peter,
Do you think the code below will work, or am I misunderstanding what you
have instructed me to do?
Michael

Public intPrintNow as Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
intPrintNow =1
End Sub

Private Sub CheckForPrint()
While (1)
If intPrintNow then
If RawPrinterHelper.SendFileToPrinter("printername",
"C:\test.prn") Then
Response.Write("OK")
Else
Response.Write("Failed")
End If
End If
Wend
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim th As New Threading.Thread(AddressOf CheckForPrint)
intPrintNow = 0
th.Start()
th.Join()
End Sub
Nov 21 '05 #10
Hi Peter,
I was a thinking of another project I am working on when I told you it was a web app. The app is a windows app. Sorry, about that. I did get the following code to work, but it seems erratic. I am setting intPrintNow throughout different parts of the program. I tried including the call to Join, but it hung up my machine just as you said below, so I removed it and inserted an Application.DoEvents in the while loop and it works--most of the time. Can you tell me what I am doing wrong. Also, I assume the new thread will end when the program ends--is this correct?
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim th As New Threading.Thread(AddressOf CheckForPrint)

intPrintNow = 0
th.Priority = ThreadPriority.BelowNormal

th.Start()

End Sub

Private Sub CheckForPrint()

While (1)

If intPrintNow Then

RawPrinterHelper.SendFileToPrinter("Ifcom Thermal Printer", "C:\iftest.prn")

intPrintNow = 0

End If

Application.DoEvents()

End While

End Sub

""Peter Huang" [MSFT]" <v-******@online.microsoft.com> wrote in message news:<u8**************@TK2MSFTNGXA03.phx.gbl>...
Hi 1) Because you are using While(1), so the loop will continue forever. 2) ASP.NET application is not similar with winform application. It is based on Request/Respose. i.e. The client post request, the server response to client in a reasonable time. th.Join() The code above mean the page_load will continue until the working thread(CheckForPrint) exit, while the working thread will not exit because the while(1), so the page_load will not exit and the client will not get response forever. So I think for a quick print we can just spawn one thread to print, while if we want to create a printer server, I think we can consider to use a winform application or a windows service and the asp.net application will sumbit the job to the windows application or windows service. Because we must response to the Asp.NET client(e.g. IE) in a reasonable time. Best regards, Peter Huang Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights.


Nov 21 '05 #11
Hi

Based on my test, the new spawned thread will not terminate if we did not
terminate it or it terminate itself even if the main thread is exit.
When it a winform application started, it will have a default thread, i.e.
the Main Thread(Winform UI thread), if we start a new thread, then the
process will have two threads.
Even if we terminate the main thread(by closing the winform window), the
other thread will keep running, and the process will not exit until all the
threads exits.
[Test codoe, the threadproc will keep running,even if we close the winform
window]
Private Sub threadproc()
Try
While True
System.Diagnostics.Debug.WriteLine(Now().ToString( ) &
System.Threading.Thread.CurrentThread.Name)
System.Threading.Thread.Sleep(3000)
End While
Catch ex As Exception
System.Diagnostics.Debug.WriteLine("Thread " & ex.ToString())
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
Dim th As New Threading.Thread(AddressOf threadproc)
th.Name = "Test Thread"
th.Start()
Catch ex As Exception
End Try
End Sub
For your scenario, you may try to control the thread state in the winform
application.
NOTE: the code below is for test purpose, you may need to change according
to your scenario.

'Give a bool value to indicate if we need to thread to exit
Dim bContinue As Boolean = False
Private Sub threadproc()
Try
While bContinue
System.Diagnostics.Debug.WriteLine(Now().ToString( ) &
System.Threading.Thread.CurrentThread.Name)
System.Threading.Thread.Sleep(1000)
End While
Catch ex As Exception
System.Diagnostics.Debug.WriteLine("Thread " & ex.ToString())
End Try
End Sub

Dim th As New Threading.Thread(AddressOf threadproc)

'Start thread
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
th.Name = "Test Thread"
bContinue = True
th.Start()
End Sub

'suspend thread if needed
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If th.ThreadState And (Threading.ThreadState.Running Or
Threading.ThreadState.WaitSleepJoin) Then
th.Suspend()
End If
End Sub

'resume the thread from suspended state
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
If th.ThreadState And Threading.ThreadState.Suspended Then
th.Resume()
End If
End Sub

'exit the thread by set the bContinue flag to false.
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
bContinue = False
If th.ThreadState And Threading.ThreadState.Suspended Then
th.Resume()
End If
End Sub
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #12
Hi Peter,
One thing I did read was that if you set the IsBackGround = True, you don't
have to worry about terminating the worker thread.
Thanks again for your help.
Michael
""Peter Huang" [MSFT]" <v-******@online.microsoft.com> wrote in message
news:nP*************@TK2MSFTNGXA03.phx.gbl...
Hi

Based on my test, the new spawned thread will not terminate if we did not
terminate it or it terminate itself even if the main thread is exit.
When it a winform application started, it will have a default thread, i.e.
the Main Thread(Winform UI thread), if we start a new thread, then the
process will have two threads.
Even if we terminate the main thread(by closing the winform window), the
other thread will keep running, and the process will not exit until all
the
threads exits.
[Test codoe, the threadproc will keep running,even if we close the winform
window]
Private Sub threadproc()
Try
While True
System.Diagnostics.Debug.WriteLine(Now().ToString( ) &
System.Threading.Thread.CurrentThread.Name)
System.Threading.Thread.Sleep(3000)
End While
Catch ex As Exception
System.Diagnostics.Debug.WriteLine("Thread " & ex.ToString())
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
Dim th As New Threading.Thread(AddressOf threadproc)
th.Name = "Test Thread"
th.Start()
Catch ex As Exception
End Try
End Sub
For your scenario, you may try to control the thread state in the winform
application.
NOTE: the code below is for test purpose, you may need to change according
to your scenario.

'Give a bool value to indicate if we need to thread to exit
Dim bContinue As Boolean = False
Private Sub threadproc()
Try
While bContinue
System.Diagnostics.Debug.WriteLine(Now().ToString( ) &
System.Threading.Thread.CurrentThread.Name)
System.Threading.Thread.Sleep(1000)
End While
Catch ex As Exception
System.Diagnostics.Debug.WriteLine("Thread " & ex.ToString())
End Try
End Sub

Dim th As New Threading.Thread(AddressOf threadproc)

'Start thread
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
th.Name = "Test Thread"
bContinue = True
th.Start()
End Sub

'suspend thread if needed
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If th.ThreadState And (Threading.ThreadState.Running Or
Threading.ThreadState.WaitSleepJoin) Then
th.Suspend()
End If
End Sub

'resume the thread from suspended state
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
If th.ThreadState And Threading.ThreadState.Suspended Then
th.Resume()
End If
End Sub

'exit the thread by set the bContinue flag to false.
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
bContinue = False
If th.ThreadState And Threading.ThreadState.Suspended Then
th.Resume()
End If
End Sub
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 21 '05 #13
Hi

Thanks for your feedback.
If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Manfred Schwab | last post by:
Recording messages and print statements in a textfile during program execution. Is there a similar command to redirect errormessages or print statements into a standart asciifile during...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
7
by: Ron | last post by:
Hi All, Is it possible to have Access print a report, identical to one that would print to a printer, only print to a "standard" text file? I can't find it in help and when I try to just print...
3
by: Max58kl | last post by:
Trying to access data and print it to the screen using Perl Builders I/O Window -------------------------------------------------------------------------------- Hi I am using a program called...
3
by: itdaddy | last post by:
hey perl gurus! i am new to this forum cause i need help. I have done many scripts. but i want to use perl to do this: What I want to do is this. I have a QRP file that I can convert to a txt...
2
by: alivip | last post by:
when I wont to inser (anyting I print) to the textbox it will not inser it just print then hanging # a look at the Tkinter Text widget # use ctrl+c to copy, ctrl+x to cut selected text, #...
12
by: Studiotyphoon | last post by:
Hi, I have report which I need to print 3 times, but would like to have the following headings Customer Copy - Print 1 Accounts Copy - Print 2 File Copy -Print 3 I created a macro to...
5
by: prakashturkar | last post by:
Hi, I am Prakash.... I have tried to print an MS Word file using the basic print utilities provided in JAVA.But while asking for printing through my own code i am getting proble for example..."The...
2
by: dmorand | last post by:
When I try to print a 'print version' of my page it looks fine in IE 7, but when I print in IE 6 the margins are all screwed up. The page itself looks the same in both browsers, it's just when I...
11
by: JWest46088 | last post by:
I'm having difficulty trying to figure out how to print a text file from a hash table one line at a time. I have the text file read into the hash table and can print the text file all at once, but I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.