如何在不使用ReportViewer的情况下从Web打印水晶报表 [英] How to print crystal report from web without using ReportViewer

查看:71
本文介绍了如何在不使用ReportViewer的情况下从Web打印水晶报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



我在visual studio 2010终极版上创建了一个基于web的asp.net项目。

我的水晶报告在我的项目,但我还没有使用reportviewer来查看它。



点击打印按钮后,将出现打印对话框并打印报告。



我编写的代码在visual studio 2010中的ASP.NET应用程序中运行良好。



但是尽快我部署了它并将其上传到服务器中,它显示错误



当应用程序未运行时显示模式对话框或表单UserInteractive模式不是有效操作。指定ServiceNotification或DefaultDesktopOnly样式以显示来自服务应用程序的通知。





我搜索了谷歌中的错误并了解了该窗口对话框不能在服务器上工作。



我在这里粘贴我的打印代码,任何人都可以帮我解决要更换的代码,以便点击打印按钮,打印服务器上出现对话框并打印我的报告。



请随时提供帮助。



我总是喜欢codeproject.com。这里的专家非常乐于助人。我不太了解javascript代码或其他。



 受保护  void  btnPrint_Click( object  sender,EventArgs e)
{
// ReportDocument rDoc = new ReportDocument();
// rDoc.Load(C:/ Users / SUDESHNA / Documents / Visual Studio 2010 / Projects / Inventory / SoldCrystalReport.rpt);
// rDoc.SetParameterValue(@ Category,ddlCategory.SelectedValue);
// rDoc.SetDatabaseLogon(sa,gariahat);
// this.crystalReportViewer.ReportSource = rDoc;
// this.crystalReportViewer.DataBind();
// this.crystalReportViewer.Focus();
// rDoc.Refresh();
// rDoc。 PrintToPrinter(1,true,0,0);

ReportDocument rDoc = new ReportDocument();
PrintDialog dialog1 = new PrintDialog();
rDoc.Load(Server.MapPath( SoldCrystalReport.rpt));
rDoc.SetParameterValue( @ Category,ddlCategory.SelectedValue);
rDoc.SetDatabaseLogon( sa gariahat);
dialog1.AllowSomePages = true ;
dialog1.AllowPrintToFile = false ;
if (dialog1.ShowDialog()== System.Windows.Forms.DialogResult.OK)
{
int copies = dialog1.PrinterSettings.Copies;
int fromPage = dialog1.PrinterSettings.FromPage;
int toPage = dialog1.PrinterSettings.ToPage;
bool collat​​e = dialog1.PrinterSettings.Collat​​e;

rDoc.PrintOptions.PrinterName = dialog1.PrinterSettings.PrinterName;
rDoc.PrintToPrinter(拷贝,整理,fromPage,toPage);
}
rDoc.Dispose();
dialog1.Dispose();





提前谢谢

请帮助

解决方案

 受保护的  Sub  printDiv()
Dim key As 字符串 = script3
Dim cstype As Type = Me GetType ()
Dim 脚本 As 字符串 = < script type =text / javascript>& vbCrLf _
+ function printDivnew(divID){& vbCrLf _
+ //获取div的HTML& vbCrLf _
+ var divElements = document.getElementById(divID).innerHTML;& ; vbCrLf _
+ //获取整页的HTML& vbCrLf _
+ var oldPage = document.body.innerHTML;& vbCrLf _
+ //仅使用div的HTML重置页面的HTML& vbCrLf _
+ document.body.innerHTML =& vbCrLf _
+ < html>< head>< title>< / title>< / head>< body>& vbCrLf _
+ divElements +< / body>;& ; vbCrLf _
+ //打印页面& vbCrLf _
+ window.print();& vbCrLf _
+ //恢复orignal HTML& vbCrLf _
+ document.body.innerHTML = oldPage;& vbCrLf _
+ }& vbCrLf _
+ < / script>
ClientScript.RegisterStartupScript(cstype,key,script)
Me .ClientScript.RegisterStartupScript(cstype,key,script)
End Sub


Hello

I had created a web based asp.net project on visual studio 2010 ultimate.
I have crystal reports in my project but I have not used reportviewer to view it.

On clicking on print button, the print dialog box should appear and reports will be printed.

The code that i had written worked fine in my ASP.NET application inside visual studio 2010.

but as soon as i deployed it and uploaded it in server, it showed a error that

Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.



I searched the error in google and came to know that windows dialog box wont work in server.

I am pasting my print code here, can anyone please help me what code to be replaced so that on clicking on print button, print dialog box appears on the server and my reports gets printed.

Kindly please help as its a need.

I always prefer codeproject.com. Here experts are very helpful. I dont have much idea about javascript code or other.

protected void btnPrint_Click(object sender, EventArgs e)
    {
        //  ReportDocument rDoc = new ReportDocument();
        //rDoc.Load("C:/Users/SUDESHNA/Documents/Visual Studio 2010/Projects/Inventory/SoldCrystalReport.rpt");
        //rDoc.SetParameterValue("@Category", ddlCategory.SelectedValue);
        //rDoc.SetDatabaseLogon("sa", "gariahat");
        //this.crystalReportViewer.ReportSource = rDoc;
        //this.crystalReportViewer.DataBind();
        //this.crystalReportViewer.Focus();
        //rDoc.Refresh();
        //rDoc.PrintToPrinter(1, true, 0, 0);

        ReportDocument rDoc = new ReportDocument();
        PrintDialog dialog1 = new PrintDialog();
        rDoc.Load(Server.MapPath("SoldCrystalReport.rpt"));
        rDoc.SetParameterValue("@Category", ddlCategory.SelectedValue);
        rDoc.SetDatabaseLogon("sa", "gariahat");
        dialog1.AllowSomePages = true;
        dialog1.AllowPrintToFile = false;
        if (dialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            int copies = dialog1.PrinterSettings.Copies;
            int fromPage = dialog1.PrinterSettings.FromPage;
            int toPage = dialog1.PrinterSettings.ToPage;
            bool collate = dialog1.PrinterSettings.Collate;

            rDoc.PrintOptions.PrinterName = dialog1.PrinterSettings.PrinterName;
            rDoc.PrintToPrinter(copies, collate, fromPage, toPage);
        }
        rDoc.Dispose();
        dialog1.Dispose();



Thanks in advance
Please kindly help

解决方案

Protected Sub printDiv()
        Dim key As String = "script3"
        Dim cstype As Type = Me.GetType()
        Dim script As String = "<script type=""text/javascript"">" & vbCrLf _
             + "function printDivnew(divID) {" & vbCrLf _
             + "//Get the HTML of div" & vbCrLf _
             + "var divElements = document.getElementById(divID).innerHTML;" & vbCrLf _
             + "//Get the HTML of whole page" & vbCrLf _
             + "var oldPage = document.body.innerHTML;" & vbCrLf _
             + "//Reset the page's HTML with div's HTML only" & vbCrLf _
             + "document.body.innerHTML =" & vbCrLf _
             + """<html><head><title></title></head><body>""" & vbCrLf _
             + "divElements + ""</body>"";" & vbCrLf _
             + "//Print Page" & vbCrLf _
             + "window.print();" & vbCrLf _
             + "//Restore orignal HTML" & vbCrLf _
             + "document.body.innerHTML = oldPage;" & vbCrLf _
             + "}" & vbCrLf _
             + "</script>"
        'ClientScript.RegisterStartupScript(cstype, key, script)
        Me.ClientScript.RegisterStartupScript(cstype, key, script)
    End Sub


这篇关于如何在不使用ReportViewer的情况下从Web打印水晶报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆