我正在使用Crystal报告在我的Appln.In我的Appln报告是在查看后下载。我想报告应该在新窗口。怎么办?在这里我将给我的代码请告诉我。 [英] I Am Using Crystal Report In My Appln.In My Appln The Report Are Download After That Viewing.I Want Report Should In New Window.How To Do?Here I Will Give My Code Please Tell Me .

查看:73
本文介绍了我正在使用Crystal报告在我的Appln.In我的Appln报告是在查看后下载。我想报告应该在新窗口。怎么办?在这里我将给我的代码请告诉我。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Imports CrystalDecisions.CrystalReports.Engine
Imports Microsoft.VisualBasic
Imports System
Imports CrystalDecisions.Web
Imports CrystalDecisions.Shared
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Globalization
Partial Class crs_fullcyl
    Inherits System.Web.UI.Page
  
    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        CrystalReportViewer1.Visible = False
        TxtToDt.Text = Format(Now, "yyyy-MM-dd")
        TxtToDt0.Text = Format(Now, "yyyy-MM-dd")
    End Sub
 
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Response.Redirect("cylinder_report.aspx?report=" & Left(DropDownList1.SelectedItem.Value, 4))
        'Response.Redirect("cylinder_report.aspx?report=" & Left(DropDownList1.SelectedItem.Value, 4))
        If Page.IsPostBack Then
            CrystalReportViewer1.Visible = False
        Else
            CrystalReportViewer1.Visible = False
        End If
        Dim RptDocument As New ReportDocument
        RptDocument.Load(Server.MapPath("reports\cyl1.rpt"))
 
        Dim flag As String = String.Empty
        If (String.Equals(DropDownList1.SelectedItem.Value, "Full Cylinders Report")) Then
            flag = "F"
        ElseIf (String.Equals(DropDownList1.SelectedItem.Value, "Empty Cylinders Report")) Then
            flag = "E"
        ElseIf (String.Equals(DropDownList1.SelectedItem.Value, "Issued Cylinders Report")) Then
            flag = "I"
        Else
            flag = "R"
        End If
 
        'Set login info
        Dim myLogin As CrystalDecisions.Shared.TableLogOnInfo
        'Dim RptDocument As New ReportDocument
        Dim myTable As Table
        For Each myTable In RptDocument.Database.Tables
            myLogin = myTable.LogOnInfo
            myLogin.ConnectionInfo.ServerName = "JPM"
            myLogin.ConnectionInfo.DatabaseName = "JPMDB"
            myLogin.ConnectionInfo.UserID = "vbreports"
            myLogin.ConnectionInfo.Password = ""
            myTable.ApplyLogOnInfo(myLogin)
            myTable.Location = myTable.Location
        Next
        CrystalReportViewer1.ReportSource = RptDocument
        
        RptDocument.Load(Server.MapPath("reports\cyl1.rpt"))
 
        'Dim flag As String = String.Empty
        If (String.Equals(DropDownList1.SelectedItem.Value, "Full Cylinders Report")) Then
            flag = "F"
        ElseIf (String.Equals(DropDownList1.SelectedItem.Value, "Empty Cylinders Report")) Then
            flag = "E"
        ElseIf (String.Equals(DropDownList1.SelectedItem.Value, "Issued Cylinders Report")) Then
            flag = "I"
        Else
            flag = "R"
        End If
 
        RptDocument.SetParameterValue(0, TxtToDt.Text)
        RptDocument.SetParameterValue(1, TxtToDt0.Text)
        RptDocument.SetParameterValue(2, flag)
 
        Dim ms As New System.IO.MemoryStream
        ms = RptDocument.ExportToStream(ExportFormatType.PortableDocFormat)
        HttpContext.Current.Response.ClearContent()
        HttpContext.Current.Response.ClearHeaders()
        HttpContext.Current.Response.ContentType = "application/pdf"
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=cylinderreport.pdf")
        HttpContext.Current.Response.BinaryWrite(ms.ToArray())
        HttpContext.Current.Response.End()
 
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
      
        If Page.IsPostBack Then
            CrystalReportViewer1.Visible = False
        Else
            CrystalReportViewer1.Visible = False
        End If
        Dim RptDocument As New ReportDocument
        RptDocument.Load(Server.MapPath("reports\cyl1.rpt"))
 
        Dim flag As String = String.Empty
        If (String.Equals(DropDownList1.SelectedItem.Value, "Full Cylinders Report")) Then
            flag = "F"
        ElseIf (String.Equals(DropDownList1.SelectedItem.Value, "Empty Cylinders Report")) Then
            flag = "E"
        ElseIf (String.Equals(DropDownList1.SelectedItem.Value, "Issued Cylinders Report")) Then
            flag = "I"
        Else
            flag = "R"
        End If
 
        'Set login info
        Dim myLogin As CrystalDecisions.Shared.TableLogOnInfo
        'Dim RptDocument As New ReportDocument
        Dim myTable As Table
        For Each myTable In RptDocument.Database.Tables
            myLogin = myTable.LogOnInfo
            myLogin.ConnectionInfo.ServerName = "JPM"
            myLogin.ConnectionInfo.DatabaseName = "JPMDB"
            myLogin.ConnectionInfo.UserID = "vbreports"
            myLogin.ConnectionInfo.Password = ""
            myTable.ApplyLogOnInfo(myLogin)
            myTable.Location = myTable.Location
        Next
        CrystalReportViewer1.ReportSource = RptDocument
       
        RptDocument.Load(Server.MapPath("reports\cyl1.rpt"))
 
        'Dim flag As String = String.Empty
        If (String.Equals(DropDownList1.SelectedItem.Value, "Full Cylinders Report")) Then
            flag = "F"
        ElseIf (String.Equals(DropDownList1.SelectedItem.Value, "Empty Cylinders Report")) Then
            flag = "E"
        ElseIf (String.Equals(DropDownList1.SelectedItem.Value, "Issued Cylinders Report")) Then
            flag = "I"
        Else
            flag = "R"
        End If
 
        RptDocument.SetParameterValue(0, TxtToDt.Text)
        RptDocument.SetParameterValue(1, TxtToDt0.Text)
        RptDocument.SetParameterValue(2, flag)
 

        Dim ms As New System.IO.MemoryStream
        ms = RptDocument.ExportToStream(ExportFormatType.ExcelRecord)
        HttpContext.Current.Response.ClearContent()
        HttpContext.Current.Response.ClearHeaders()
        HttpContext.Current.Response.ContentType = "application/excel"
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=cylinderreport.xls")
        HttpContext.Current.Response.BinaryWrite(ms.ToArray())
        HttpContext.Current.Response.End()
 
    End Sub
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack = True Then
            TxtToDt.Text = Format(Now, "yyyy-MM-dd")
            TxtToDt0.Text = Format(Now, "yyyy-MM-dd")
        End If
    End Sub
 
End Class

推荐答案

替换此:



replace this:

ms = RptDocument.ExportToStream(ExportFormatType.PortableDocFormat)





这个:





with this:

ms = RptDocument.ExportToHTTPResponse(ExportFormatType.PortableDocFormat,Response,True,"Exported Report")


这篇关于我正在使用Crystal报告在我的Appln.In我的Appln报告是在查看后下载。我想报告应该在新窗口。怎么办?在这里我将给我的代码请告诉我。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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