I have a function for exporting reports directly to pdf that works great but I want to be able to redirect the user once the report is generated and can't seem to make that happen. I either can redirect the user or print the report and the user stays on the page. Here is the code I use for the export, taken from a blog on this site. Works great.
I was told to remove the last line that ends the request and add this:
But that didn't work, it only redirected me to the new page but no report got generated. Here is the code I use to generate the report:
Any help would be appreciated.
Public Function ExportToPDF(ByVal reportToExport As Telerik.Reporting.Report) As Telerik.Reporting.Report Dim reportProcessor As New Telerik.Reporting.Processing.ReportProcessor() Dim result As RenderingResult = reportProcessor.RenderReport("PDF", reportToExport, Nothing) Dim fileName As String = result.DocumentName + ".pdf" HttpContext.Current.Response.Clear() HttpContext.Current.Response.ContentType = result.MimeType HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Private) HttpContext.Current.Response.Expires = -1 HttpContext.Current.Response.Buffer = True 'Uncommenting the following line will prompt user to Open Save or Cancel. Otherwise report opens in new window HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("{0};FileName=""{1}""", "attachment", fileName)) HttpContext.Current.Response.BinaryWrite(result.DocumentBytes) HttpContext.Current.Response.End() End FunctionHttpContext.Current.Response.Redirect("../WorkOrders/OpenWorkOrdersSummary.aspx", True)If ChkPrint.Checked = True Then Dim tF As New TelerikFunctions Dim rv = New FacilitiesReportsLibrary.WorkOrder rv.setWorkOrderID = Session("WorkOrderID") tF.ExportToPDF(rv) Else Response.Redirect("../WorkOrders/OpenWorkOrdersSummary.aspx") End If