Click here to Skip to main content
15,880,972 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
The below code is working fine for local printer i.e ("HP LaserJet 1020" -- whichi is installed and connected to my server), but i want to take printout from my network printer i.e ("\\\\ADMIN\HP LaserJet 1020") which is set as a default printer in my server machine.( VS2010, SAP CRYSTAL REPORTS FOR VS2010, ASP.NET, C#)


try
{
ExportOptions CrExportOptions;

DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();

PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();

CrDiskFileDestinationOptions.DiskFileName = @"D:\\PDF\\" + Regno.ToString() + " (" + Prnt_Id + ")"+".PDF" ;

CrExportOptions = cryPrntRpt.ExportOptions;

{
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
}
cryPrntRpt.Export();

cryPrntRpt.PrintOptions.PrinterName = "HP LaserJet 1020";
cryPrntRpt.PrintToPrinter(1, true, 1, 1);
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "alert",
"alert('No Printer Selected');", true);
}
Posted
Updated 2-Apr-15 9:48am
v3
Comments
Sinisa Hajnal 2-Apr-15 7:31am    
Put network printer name into printer name and you're done. FULL printer name
Member 10989312 2-Apr-15 7:50am    
Thanks for your reply, I tried the below lines i am getting the error. ".Invalid printer specified."

cryPrntRpt.PrintOptions.PrinterName = @"\\\\ADMIN\\HP LaserJet 1020";
Sinisa Hajnal 2-Apr-15 8:37am    
Can you print to that printer from the computer manually? Try with some text file or PDF.

Check if printer name with spaces has to be escaped or boxed in somehow (like you have to put quotes around database table names with spaces.
Member 10989312 2-Apr-15 12:21pm    
Yes, i am able to print all documents from my system
Richard Deeming 2-Apr-15 9:04am    
Have you tried without doubling-up the backslashes?
cryPrntRpt.PrintOptions.PrinterName = @"\\ADMIN\HP LaserJet 1020";

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