Click here to Skip to main content
15,168,085 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello,


I'm using the following code to get list of printers connected to my computer
C#
 foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
{
      DropDownList1.Items.Add(printer);
}


This works fine with Visual Studio debugging, but when i upload the same to server is giving problem

C#
Server Error in '/' Application.

The RPC server is unavailable

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. 

Exception Details: System.ComponentModel.Win32Exception: The RPC server is unavailable

Source Error: 


Line 47:                 DropDownList1.Items.Add("Select");
Line 48: 
Line 49:  foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
Line 50:                 {
Line 51:                     DropDownList1.Items.Add(printer);

Source File: d:\inetpub\vhosts\interactivelogestic.com\httpdocs\CargoManagementDomainCopy\billprint.aspx.cs    Line: 49 

Stack Trace: 


[Win32Exception (0x80004005): The RPC server is unavailable]
   System.Drawing.Printing.PrinterSettings.get_InstalledPrinters() +455
   Inventry.customerledger.Page_Load(Object sender, EventArgs e) in d:\inetpub\vhosts\interactivelogestic.com\httpdocs\CargoManagementDomainCopy\billprint.aspx.cs:49
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +92
   System.Web.UI.Control.LoadRecursive() +54
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18055


I want to use printer for multiple printing of crystal report files more than 10 and all are differnt files.

Please somebody help me on this

Thanks.
Posted
Updated 2-Feb-14 20:47pm
v2
Comments
Marc Gabrie 3-Feb-14 10:41am
   
when debugging, your machine acts like the server & the client machines at the same time, that's why your code works. But when you deploy your website to another server machine, then your asp.net code will run there NOT on the client machine.

Now, the question... Do you want to get a list of the installed printers at the client machine? If yes, for what purpose?
M.Abdul Rahman 5-Feb-14 1:07am
   
i have to select the printer from dropdownlist and send approx. 30 crystal reports to print at one time

Refer - How to get client side printer list in ASP.NET?[^].
Quote:
A Web application does not have access to client systems, for a good reason. Imagine for a second that it was possible. Would any reasonable user like that some unknown site could discover printers or other equipment? This even sounds scary.
To get the printer installed at the client from an ASP.NET webpage you need to use some client tech like Flash or Silverlight or Java Applets or something else. One possible solution could be developing something like this http://goo.gl/eFSPw where the report is exported to PDF for printing purposes. You could export your reports to PDF, merge all of them in order into 1 single PDF file (using PDFSharp) and embed some javascript print code as stated here http://www.vo1dmain.info/pdfsharp-howto-inject-javascript-into-pdf-autoprinting-functionality again using PDFSharp
   

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