Trouble Generating a PDF file from a ReportViewer control RRS feed

  • Question

  • I am trying to generate a PDF file from a ReportViewer control when a user selects a Save button, but cannot understand the behavior I am experiencing.

    When I click the Save button the first time, no data is present on the PDF file created.  When I click the Save button the SECOND time, it works and I get data in the report/PDF.  Since I am trying to automate the generation of the PDF files, at some point there must be no clicking, so having to click twice is not condusive to my objective.

    Here is the code executed when the Save button is pressed:

        private void CreatePDF(string fileName)
            // Variables
            Warning[] warnings;
            string[] streamIds;
            string mimeType = "application/pdf";
            string encoding = string.Empty;
            string extension = string.Empty;

            fileName = "Test2";
            byte[] bytes = ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);

            // Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
            Response.Buffer = true;
            Response.ContentType = mimeType;
            Response.AddHeader("content-disposition", "attachment; filename=" + fileName + "." + extension);
            Response.BinaryWrite(bytes); // create the file
            //Response.Flush(); // send it to the client to download

    The parameters for the 10 data sources I have all point to 2 textboxes.

    Any help would be greatly appreciated!


    • Moved by Fred Bao Wednesday, August 5, 2015 9:55 AM VS Report Related
    Tuesday, August 4, 2015 10:21 PM

All replies

  • Hi PBurg99,

    Like your title mentioned your case more related to ReportViewer control, for a better support, I moved your case to Visual Studio Report Controls forum. 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Edited by Kristin Xie Wednesday, August 5, 2015 9:57 AM
    Wednesday, August 5, 2015 9:57 AM
  • Thanks!
    Wednesday, August 5, 2015 3:17 PM