This is a migrated thread and some comments may be shown as answers.

How to open report as pdf directly to IE 7 window

5 Answers 188 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
AkAlan
Top achievements
Rank 2
AkAlan asked on 22 Sep 2009, 05:52 PM
I have some code in a class that I use to export a report to pdf without having to use a report viewer and it works great except that the user is always prompted to Open or Save the report. I want the report to open directly in a new page without the prompt. I also would like to make the cursor change while the report is rendering so the user knows the print button was actually clicked. Thanks for any help.


He is my class code :
Imports Microsoft.VisualBasic  
Imports Telerik.Reporting.Processing  
Imports MyTelerikLibrary  
Public Class TelerikFunctions  
    Inherits System.Web.UI.Page  
    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 
 
        HttpContext.Current.Response.AddHeader("Content-Disposition"String.Format("{0};FileName=""{1}""""attachment", fileName))  
        HttpContext.Current.Response.BinaryWrite(result.DocumentBytes)  
        HttpContext.Current.Response.End()  
    End Function 
End Class 
Here is the Buttons click event (along with page declarations)
 Imports Telerik.Reporting.Processing

 

Imports MyTelerikLibrary  

 

Dim tF As New TelerikFunctions  
Dim rv = New RwpListingD007()  
tF.ExportToPDF(rv)  
 

5 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 23 Sep 2009, 07:17 AM
Hello AkAlan,

The Open/Save dialog is browser behavior and cannot be controlled by the code used for exporting. If there is an option to open the document directly, it should be an option of the pdf browser plugin used to open the file.

All the best,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Accepted
Ramón
Top achievements
Rank 1
answered on 07 Oct 2009, 10:57 AM
Hi, AkAlan.

Just remove the following line and it will open directly in  the browser window (tested in IE8)

 HttpContext.Current.Response.AddHeader("Content-Disposition"String.Format("{0};FileName=""{1}""""attachment", fileName))  

Regards,

Ramón.
0
AkAlan
Top achievements
Rank 2
answered on 07 Oct 2009, 03:04 PM
Thanks Ramón,  That works exactly as I had wanted, and so simple. I am still on IE 7 and it work with that.
0
Ramón
Top achievements
Rank 1
answered on 08 Oct 2009, 09:00 AM
Hi, AkAlan.

Great it worked for you.

I was looking for hours for a solution to my problem.  I finally googled for "Content-Disposition" to know what it does, so I found that it forces the browser to show an open/save dialog for known MIME types, as in "http://support.microsoft.com/kb/260519".   I just removed it from code.

Regards,

Guillermo
0
prateek
Top achievements
Rank 1
answered on 17 Jul 2017, 08:48 AM

Hi You can do this simply by applying event -  OnClientClick="aspnetForm.target ='_blank';" 

 <asp:Button ID="exportPDF" runat="server" target="blank" Text="Export PDF" OnClientClick="aspnetForm.target ='_blank';" CssClass="btn btn-info" />

Tags
General Discussions
Asked by
AkAlan
Top achievements
Rank 2
Answers by
Steve
Telerik team
Ramón
Top achievements
Rank 1
AkAlan
Top achievements
Rank 2
prateek
Top achievements
Rank 1
Share this question
or