Click here to Skip to main content
15,886,091 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
dear all,

I am making a Web Part for a sharepoint site with .NET (visual studio 2010).

How can I add a button in my web part, clicking on which will print a .text file stored on my server's c: drive to

a printer on the client side without prompting for a 'print' dialogue box?

The file to be printed is in the server's c: drive where the sharepoint site is hosted.

The printer will be a local printer attached to the client machine.

I have used the code at http://www.dotnetspider.com/resources/43366-Printing-Datatable-Data-In-C.aspx for creating

the .text file.

Please suggest.

Thanks in advance.
Posted

You can't change how the browser works. However, you should know that the code that you've copied, will not work all, and if you change the folder it stores the txt file in, in order that your web site would have access to it, it will print your document using whatever printer is attached to the server. It's clear you don't understand this code, or how the web works. C# code runs on the server. When you test, the server and the client are the same, but when someone looks at your page, they are not. The only way to print a web page, is to use window.print() in a browser window that is showing what you want printed, and nothing more. You can't get around getting a dialogue box asking you what printer to use.
 
Share this answer
 
Comments
nagen bihari 26-Jul-12 1:34am    
Thanks for the reply.

What about printing the .txt file to a network printer with an IP address?
I have seen .NET applications(in restaurants) where when one places an order and clicks confirm, a dynamic crystal report is generated and the same is printed from a network printer directly--without prompting for a print dialogue box.

Any suggestions?
bbirajdar 26-Jul-12 10:42am    
Have you observed it keenly ? Those are desktop applications and not web applications..
nagen bihari 27-Jul-12 6:32am    
Those are certainly Web Applications. I have the source code for a simple Web Based Application for Billing. But here the reports are generated in Crystal Report and directly send to a Network Printer on confirming the order. The end user only gets the illusion that-'click the confirm order button and get the slip from the printer'.
The same I want to do with a .txt file----which of course I don't know how!
bijumonjoseph 18-Oct-13 4:23am    
Can you send me the code. I have a similar issue of printing receipt directly on the printer.

Regards
Biju
bijumonjoseph 18-Oct-13 4:23am    
Can you send me the code. I have a similar issue of printing receipt directly on the printer.

Regards
Biju
Dear all

Finally, I have solved the problem.

Made a .dll filr from the link http://stackoverflow.com/questions/3507187/how-to-print-a-pcl-file-in-c.

Added the dll to the GAC.

Call it in my code.....and voila.......It prints my text file.

Note that I am using a HP Laserjet P2015 PCL6.

......Thanks to all for your valuable guidance.

...and for those who thought it was IMPOSSIBLE, take a look at the above link.

Thank you all again!
 
Share this answer
 
Comments
bbirajdar 28-Jul-12 6:08am    
Great..thank you for posting the solution
chitrakantsahu 2-Dec-22 7:58am    
Dear Nagen,

I want to print word file from client printer how can I do that? It is an intranet application built in mvc c#.

Can you code help me to achieve this.
The print dialog prompt is a security feature built into the browsers so that you should not waste the users' printing paper by printing your company's pizza menus whenever the user visits your website ... :). You own the website, not the users' printer and the paper. Let him decide whether to print or not.

It cannot be disabled since this is how the browser works. Even if it could be disabled ( I don't know how, but if somebody really does ), it would be a security breach or hack for which this forum does not provide any code or solution.
 
Share this answer
 
v3
Comments
nagen bihari 27-Jul-12 6:24am    
Thanks for the reply.
But what about a network printer? I want a predefined network printer to print a .txt file on click of a button without prompting for a print dialogue. 'JUST CLICK AND GET A PRINTOUT' type.
Any help with the code please?
bbirajdar 27-Jul-12 6:52am    
You are not getting the point. Its the difference between the "desktop application" and "web application". A web application makes no difference between a network printer and a local printer. If you give a PRINT command via a web browser in ANY ANY way, it will show the prompt.. There is no bypassing for this functionality. So printing ( whether with local printer or network printer) using web app is NOT possible with your 'JUST CLICK AND GET A PRINTOUT'. But it works with windows app.


Some body here http://www.daniweb.com/web-development/aspnet/threads/200452/printing-at-client-side-without-print-dialog-box it works but use it at your own risk
nagen bihari 27-Jul-12 23:23pm    
Thanx.
But don't say it is not possible. I have the code for a Web Application that print crystal reports to a predefined network printer just on click of a button without prompting for 'Print' dialogue. But not able to figure out how to do the same for a text file!
bijumonjoseph 18-Oct-13 4:21am    
Can you send me the code. I have a similar issue and need to print receipt directly to the printer.

Thanks
Biju
Er Atul Sharma 15-May-15 4:04am    
Hi,
can you send this code to me please, i have a similar issue and need to print directly to printer, on my mail id is atulsharmaaa1987@gmail.com ASAP., its urgent to me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900