locked
Reports RRS feed

  • Question

  • User1016820894 posted

    I have the code below to render a pdf report on the screen. When this code is executed in Edge or Chrome it is creating a pdf file in my default folder on my local machine. In IE it does not (prompts user to open/save. How can I modify the code so that it doesn't physically save a copy of the report in Edge/Chrome. Note - I tried using "inline" but that opens it up in the current window and for security reasons we don't have the navigation buttons available so closing the report out closes the entire app. Or is there some way to do "inline" and open the report in a new window?

    Thanks.

    byte[] bytesret = ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out fileNameExtension, out streamids, out warnings);

    Response.Buffer = false;

    Response.Clear();

    Response.ClearHeaders();

    Response.ClearContent();

    Response.ContentType = "application/PDF";

    Response.Cache.SetCacheability(HttpCacheability.NoCache);

    Response.AddHeader("content-disposition", "attachment; filename=" + fileName);

    Response.BinaryWrite(bytesret); // create the file

    Response.Flush();

    Tuesday, April 14, 2020 1:08 PM

All replies

  • User288213138 posted

    Hi baldwinjohn,

    When this code is executed in Edge or Chrome it is creating a pdf file in my default folder on my local machine. In IE it does not (prompts user to open/save. How can I modify the code so that it doesn't physically save a copy of the report in Edge/Chrome.

    I tested your code in all three browsers, but in Edge it will prompt users to open/save.

    The resulr in edge:

    If you want to prompt user when download the file, you can try to Content-Disposition header.

    More information about the use of Content-Disposition header you can refer to this link:

    https://weblog.west-wind.com/posts/2007/may/21/downloading-a-file-with-a-save-as-dialog-in-aspnet

    Best regards,

    Sam

    Wednesday, April 15, 2020 3:59 AM