Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open report in PDF and close the form behind

Status
Not open for further replies.

Strobeman

Programmer
May 16, 2003
40
AU
In order to open two reports at the same time I have had to open two forms which then prompt the user to open or save the pdf report. Once the report is open I would like to close the form behind but so far have not had any luck.

I am using the following code to open the pdf.

Dim _reportManager As New ReportManager
Dim LocalReport As New LocalReport()
Dim reportType As String = "PDF"
Dim mimeType As String = ""
Dim encoding As String = ""
Dim fileNameExtension As String = ""

Dim deviceInfo As String = "<DeviceInfo>" + " <OutputFormat>PDF</OutputFormat>" + " <PageWidth>8.3in</PageWidth>" + _
" <PageHeight>11.7in</PageHeight>" + " <MarginTop>0.5in</MarginTop>" + " <MarginLeft>1in</MarginLeft>" + " <MarginRight>1in</MarginRight>" + _
" <MarginBottom>0.5in</MarginBottom>" + "</DeviceInfo>"

Dim warnings() As Warning = Nothing
Dim streams() As String = Nothing
Dim renderedBytes() As Byte

Dim CreatedDateFrom As String = Session("CreatedDateFrom").ToString()
Dim CreatedDateTo As String = Session("CreatedDateTo").ToString()
Dim ConfirmedDateFrom As String = Session("ConfirmedDateFrom").ToString()
Dim ConfirmedDateTo As String = Session("ConfirmedDateTo").ToString()
Dim ReceivedFrom As String = Session("ReceivedFrom").ToString()
Dim ReceivedTo As String = Session("ReceivedTo").ToString()

Dim _ds As DataSet = _reportManager.RunBusinessReport_ConfirmingBusinessRegistrationDetailsReport(0, True, IIf(CreatedDateFrom = "", Nothing, CreatedDateFrom), IIf(CreatedDateTo = "", Nothing, CreatedDateTo), IIf(ConfirmedDateFrom = "", Nothing, ConfirmedDateFrom), IIf(ConfirmedDateTo = "", Nothing, ConfirmedDateTo), IIf(ReceivedFrom = "", Nothing, ReceivedFrom), IIf(ReceivedTo = "", Nothing, ReceivedTo))
LocalReport.ReportPath = Server.MapPath("~/Reports/ReportRSTemplates/BusinessConfirmBusinessRegistrationDetails.rdlc")
LocalReport.DataSources.Add(New Microsoft.Reporting.WebForms.ReportDataSource("dsConfirmBusinessRegistrationDetails_msp_Report_Business_BusinessConfirmDetails_RS", _ds.Tables(0)))

renderedBytes = LocalReport.Render(reportType, deviceInfo, mimeType, encoding, fileNameExtension, streams, warnings)

Response.Clear()
Response.ContentType = mimeType
Response.AddHeader("content-disposition", "attachment; filename=CBRReport." + fileNameExtension)
Response.BinaryWrite(renderedBytes)
Response.End()


I tried to get the following code to run in Page_LoadComplete but the Response.End() stops all other code from running.

Dim strscript As String = "<script language=javascript>window.top.close();</script>"
If (Not ClientScript.IsStartupScriptRegistered("clientScript")) Then
ClientScript.RegisterStartupScript(Me.GetType(), "clientScript", strscript)
End If

Can anybody offer any advice?
Much appreciated.
 
Ask in the javascript forum, I think it is somethig like window.opener.location
 
Thanks very much. I eventually just decided to display the report in the same window using the following code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim _reportManager As New ReportManager
Dim CreatedDateFrom As String = Session("CreatedDateFrom").ToString()
Dim CreatedDateTo As String = Session("CreatedDateTo").ToString()
Dim ConfirmedDateFrom As String = Session("ConfirmedDateFrom").ToString()
Dim ConfirmedDateTo As String = Session("ConfirmedDateTo").ToString()
Dim ReceivedFrom As String = Session("ReceivedFrom").ToString()
Dim ReceivedTo As String = Session("ReceivedTo").ToString()

Dim reportType As String = "PDF"
Dim mimeType As String = ""
Dim encoding As String = ""
Dim fileNameExtension As String = ""
Dim deviceInfo As String = "<DeviceInfo>" + " <OutputFormat>PDF</OutputFormat>" + " <PageWidth>8.3in</PageWidth>" + _
" <PageHeight>11.7in</PageHeight>" + " <MarginTop>0.5in</MarginTop>" + " <MarginLeft>1in</MarginLeft>" + " <MarginRight>1in</MarginRight>" + _
" <MarginBottom>0.5in</MarginBottom>" + "</DeviceInfo>"
Dim warnings() As Warning = Nothing
Dim streams() As String = Nothing
Dim renderedBytes() As Byte

Dim _ds As DataSet = _reportManager.RunBusinessReport_ConfirmingBusinessRegistrationDetailsReport(0, True, IIf(CreatedDateFrom = "", Nothing, CreatedDateFrom), IIf(CreatedDateTo = "", Nothing, CreatedDateTo), IIf(ConfirmedDateFrom = "", Nothing, ConfirmedDateFrom), IIf(ConfirmedDateTo = "", Nothing, ConfirmedDateTo), IIf(ReceivedFrom = "", Nothing, ReceivedFrom), IIf(ReceivedTo = "", Nothing, ReceivedTo))

ReportViewer1.ProcessingMode = ProcessingMode.Local
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reports/ReportRSTemplates/BusinessConfirmBusinessRegistrationDetails.rdlc")
ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WebForms.ReportDataSource("dsConfirmBusinessRegistrationDetails_msp_Report_Business_BusinessConfirmDetails_RS", _ds.Tables(0)))

renderedBytes = ReportViewer1.LocalReport.Render(reportType, deviceInfo, mimeType, encoding, fileNameExtension, streams, warnings)

Response.Buffer = True
Response.Clear()
Response.ContentType = mimeType
Response.BinaryWrite(renderedBytes)
Response.Flush()
Response.End()

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top