How to open report as pdf directly to IE 7 window

5 posts, 1 answers
  1. AkAlan
    AkAlan avatar
    121 posts
    Member since:
    Jun 2009

    Posted 22 Sep 2009 Link to this post

    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 :
    1 Imports Microsoft.VisualBasic  
    2 Imports Telerik.Reporting.Processing  
    3 Imports MyTelerikLibrary  
    4 Public Class TelerikFunctions  
    5     Inherits System.Web.UI.Page  
    6     Public Function ExportToPDF(ByVal reportToExport As Telerik.Reporting.Report) As Telerik.Reporting.Report  
    7  
    8         Dim reportProcessor As New Telerik.Reporting.Processing.ReportProcessor()  
    9         Dim result As RenderingResult = reportProcessor.RenderReport("PDF", reportToExport, Nothing)  
    10  
    11         Dim fileName As String = result.DocumentName + ".pdf" 
    12         HttpContext.Current.Response.Clear()  
    13         HttpContext.Current.Response.ContentType = result.MimeType  
    14         HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Private)  
    15         HttpContext.Current.Response.Expires = -1  
    16         HttpContext.Current.Response.Buffer = True 
    17  
    18         HttpContext.Current.Response.AddHeader("Content-Disposition"String.Format("{0};FileName=""{1}""""attachment", fileName))  
    19         HttpContext.Current.Response.BinaryWrite(result.DocumentBytes)  
    20         HttpContext.Current.Response.End()  
    21     End Function 
    22 End Class 
    Here is the Buttons click event (along with page declarations)
     Imports Telerik.Reporting.Processing

     

    Imports MyTelerikLibrary  

     

    1 Dim tF As New TelerikFunctions  
    2 Dim rv = New RwpListingD007()  
    3 tF.ExportToPDF(rv)  
    4  

  2. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 23 Sep 2009 Link to this post

    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.
  3. DevCraft banner
  4. Answer
    Ramón
    Ramón avatar
    10 posts
    Member since:
    Jun 2005

    Posted 07 Oct 2009 Link to this post

    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.
  5. AkAlan
    AkAlan avatar
    121 posts
    Member since:
    Jun 2009

    Posted 07 Oct 2009 Link to this post

    Thanks Ramón,  That works exactly as I had wanted, and so simple. I am still on IE 7 and it work with that.
  6. Ramón
    Ramón avatar
    10 posts
    Member since:
    Jun 2005

    Posted 08 Oct 2009 Link to this post

    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
Back to Top
DevCraft banner