Windows应用程序中如何在Vb.net或C#.net中将水晶报表直接打印到网络打印机
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/680315/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to printing crystal report directly to network printer in Vb.net or C#.net in Windows Applications
提问by sivakumar
I have written the following code as,
我写了以下代码,
Dim report As New ReportDocument
report.PrintOptions.PrinterName = "\network\printer"
report.Load(CrystalReportName.rpt, OpenReportMethod.OpenReportByDefault)
report.PrintToPrinter(1, False, 0, 0)
when i am trying to run this code , it shows the error message as "Invalid Printer Specified". If i give the local printer name, it is working fine. But i can't able to print the crystal report directly to the network printer. Kind help needed. Thanks in advance.
当我尝试运行此代码时,它将错误消息显示为“指定的打印机无效”。如果我给本地打印机名称,它工作正常。但是我无法将水晶报告直接打印到网络打印机。需要帮助。提前致谢。
Sivakumar.P
西瓦库玛
采纳答案by lakshmanaraj
May be the printer name is wrong.
可能是打印机名称错误。
Please use the following code to debug what name is coming while choosing the network printer
请使用以下代码调试选择网络打印机时出现的名称
http://www.codeproject.com/KB/printing/printtoprinter.aspx
http://www.codeproject.com/KB/printing/printtoprinter.aspx
and then assign proper name.
然后分配正确的名称。
Still if incase it did not work out, there might be a permission issue then look at
尽管如此,如果它没有解决,可能存在许可问题,然后查看
http://forums.asp.net/t/1383129.aspx
http://forums.asp.net/t/1383129.aspx
Best of luck,.
祝你好运,。
回答by Fernando
Use this code to know the installed printers
使用此代码了解已安装的打印机
Imports System.Drawing
Imports System.Drawing.Printing
and this code on the load function... you will fill a combobox with the printers and their names correctly, and then use your code
以及加载函数上的这段代码......您将正确填写打印机及其名称的组合框,然后使用您的代码
For Each Printer In PrinterSettings.InstalledPrinters
cmbPrinters.Items.Add(Printer)
Next
回答by Rene Lapizco
For anyone having a similar problem this can be a solution:
对于任何有类似问题的人,这可以是一个解决方案:
report.PrintOptions.PrinterName = "\\\\network\\printer"
回答by sujju
In ASP.Net, a simple and sweet solution consists in install same printer drivers(like hp or zebraa) including version in both server and clinet meachine it will work with @\\\ipaddress\printername
.
在 ASP.Net 中,一个简单而甜蜜的解决方案包括安装相同的打印机驱动程序(如 hp 或 zebraa),包括服务器和 clinet 机器中的版本,它将与@\\\ipaddress\printername
.
回答by WARRIOR
In case anyone else still has this problem:
如果其他人仍然有这个问题:
In the crystal report document you are trying to print, go to:
在您尝试打印的水晶报告文档中,转到:
Design --> Page Setup
设计 --> 页面设置
A default printer not installed on your server side may have been selected. Remove or replace it and save the document. Then run your .Net code to set the printer dynamically if you want.
可能已选择未安装在服务器端的默认打印机。删除或替换它并保存文档。如果需要,然后运行您的 .Net 代码以动态设置打印机。
回答by adnan umar
User 4 backslashes i.e \\ before Network and 2 backslashes i.e \ before printername
用户 4 个反斜杠,即网络之前的 \\ 和 2 个反斜杠,即打印机名称之前的 \
\\[Network Address]\[printer name]