473,396 Members | 1,774 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,396 software developers and data experts.

C# onclick printing to printer on server

I'm not all that great at coding and I've been searching everywhere for the past couple of weeks for a remedy. I threw some code together, but am getting error codes out the wazoo.

So, what I'm attempting to do is this:

I built a web form (.aspx) using c# and it will be used as an order form of sorts for one of our departments. What I'm trying to do is to set up a "Submit" button that when clicked on, sends this document, or web form, to a printer on our network, along with having the information extracted, and inserted into a database that I've already built and sits on a sql server.

Again, I know squat about coding and have looked everywhere. I'm extremely confused and pretty much frustrated.

Please help. I'll answer any questions :)

Thank you in advance.

Here's my .cs code:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2.  
  3. using System.Data;
  4.  
  5. using System.Configuration;
  6.  
  7. using System.Management;
  8.  
  9. using System.Drawing;
  10.  
  11. using System.Drawing.Printing;
  12.  
  13. using System.Collections.Generic;
  14.  
  15. using System.IO;
  16.  
  17. using System.Linq;
  18.  
  19. using System.Text;
  20.  
  21. using System.Web;
  22.  
  23. using System.Web.Security;
  24.  
  25. using System.Web.UI;
  26.  
  27. using System.Web.UI.WebControls;
  28.  
  29. using System.Web.UI.WebControls.WebParts;
  30.  
  31. using System.Web.UI.HtmlControls;
  32.  
  33. using System.Web.SessionState;
  34.  
  35. using System.Windows.Forms;
  36.  
  37.  
  38.  
  39. public partial class ShopFillForm : System.Web.UI.Page
  40.  
  41. {
  42.  
  43. protected void Page_Load(object sender, EventArgs e)
  44.  
  45. {
  46.  
  47. int OrderID = 0;
  48.  
  49. l_Date.Text = DateTime.Now.ToString("MM-dd-yy hh:mm");
  50.  
  51. }
  52.  
  53. protected void b_submit_Click(object sender, EventArgs e)
  54.  
  55. {
  56.  
  57. // Event handler code
  58.  
  59. PrintDocument doc = new PrintDocument();
  60.  
  61. doc.PrinterSettings.PrinterName = "PRINTER on SERVER";
  62.  
  63. doc.PrintPage += new PrintPageEventHandler(this.b_submit_Click);
  64.  
  65. doc.Print();
  66.  
  67. }
  68.  
  69. }
  70.  
  71. And here's what I've got on the document regarding the submit/print button:
  72.  
  73. <asp:Button id="b_submit" runat="server" Text="Submit" style="text-align: center" 
  74.  
  75. onclick="b_submit_Click" />
  76.  
  77.  
  78.  
  79. If I'm doing something wrong or missing something, please let me know.
  80.  
  81. When I click submit, it shows that its trying to do something, but it goes to error.
  82.  
  83. Here is the error:
  84.  
  85. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  86.  
  87. Exception Details: System.Drawing.Printing.InvalidPrinterException: Settings to access printer 'UPCOLOR on print.pdxftl.com' are not valid.
  88.  
  89. Source Error: 
  90.  
  91.  
  92.  
  93. Line 32:         doc.PrinterSettings.PrinterName = "UPCOLOR on print.pdxftl.com";
  94. Line 33:         doc.PrintPage += new PrintPageEventHandler(this.b_submit_Click);
  95. Line 34:         doc.Print();
  96. Line 35:     }
  97. Line 36: }
  98.  
  99.  
  100.  
  101. Source File: y:\ShopFillForm.aspx.cs    Line: 34 
  102.  
  103. Stack Trace: 
  104.  
  105.  
  106.  
  107. [InvalidPrinterException: Settings to access printer 'UPCOLOR on print.pdxftl.com' are not valid.]
  108.    System.Drawing.Printing.PrinterSettings.GetHdevmodeInternal(String printer) +199360
  109.    System.Drawing.Printing.PrinterSettings.GetHdevmodeInternal() +28
  110.    System.Drawing.Printing.PrinterSettings.GetHdevmode(PageSettings pageSettings) +48
  111.    System.Drawing.Printing.PrintController.OnStartPrint(PrintDocument document, PrintEventArgs e) +71
  112.    System.Windows.Forms.PrintControllerWithStatusDialog.OnStartPrint(PrintDocument document, PrintEventArgs e) +30
  113.    System.Drawing.Printing.PrintController.Print(PrintDocument document) +208
  114.    System.Drawing.Printing.PrintDocument.Print() +111
  115.    ShopFillForm.b_submit_Click(Object sender, EventArgs e) in y:\ShopFillForm.aspx.cs:34
  116.    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9752490
  117.    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +196
  118.    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
  119.    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
  120.    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
  121.    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
Jul 29 '14 #1
0 1732

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: James | last post by:
how come when i print programicly my printer says "data received" and it won't print until i press the GO button on the printer? my printer is a HP laser jet 5 Set objFS =...
4
by: Suzanka | last post by:
Hello, I have an application written in C# on visual studio .NET. It is a web aplication. The application consists of many different forms, that users occassionaly want to print out for filing....
1
by: Travis Newman | last post by:
In C# .NET...I would like to write onto a PDF document with text from the database(like www.tallcomponents.com), then send the PDF to the physical printer in a looped batch print mode (50 PDFs...
3
by: Ahmad Abu-Raddad | last post by:
Hey Guys, Does anyone knows of a way to print HTML source directly to the printer (Server Side)?. I tried the PrintDocument class and the e.Graphics.DrawString and e.Graphics.DrawImage() but...
2
by: ryanp | last post by:
Printing From Server ASP.NET Anyone have a good solution for easily printing files of different types programmically... for example word documents, photoshop psd files, jpeg's, xls documents,...
1
by: Aaron Bronow | last post by:
I have an asp.net application which loads a Crystal Reports ReportDocument, passes in parameters for selecting data from the report's database connection, renders the report for previewing on the...
3
by: Franck | last post by:
Hi, Is it possible to extract all controls from a webform and print them ? I'm currently trying to use a viewstate system but can't figure out how to retrieve control position. Thks for help.
5
by: Raman | last post by:
Hello friends, I want to print an ID card. I have one Windows Form that contains front and back side. The printer is printing both front and back side at a time. I am trying to send both sides...
0
by: aleemkhan | last post by:
I am using SQL Server 2005 Local Reports for a web based project. The problem is that the ASP.NET default Web Report Viewer does not have print facility for Local Reports. When the report is...
1
by: =?Utf-8?B?Z2xheml6?= | last post by:
Last month, i updated my server 2003 to sp2. After update done, it have a problem, the folder C:\WINDOWS\system32\spool\PRINTERS is exist many print temp files and can not delete when print out...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.