Reportviewer Webforms Download option issue

Antony Durai 0 Reputation points
2023-06-17T05:27:09.2133333+00:00

Hi,

I am using Microsoft report viewer control to show and download the report in Local Mode.

But when i dowlonad the report file is coming empty.

i have full permission in Temp folder.still the file is getting downloaded with out content.

Please suggest

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,492 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Albert Kallal 5,251 Reputation points
    2023-06-17T20:04:29.33+00:00

    Ok, assuming the report does render on the page (and works).

    Then the idea (I assume) is to have a button to download the report.

    I quite sure the "mine" type has to be set. Note that the MineMapping does require .net 4.5 or later.

    This works:

                string mineType = "";
                string Encoding = "";
                Microsoft.Reporting.WebForms.Warning[] warnings;
                string[] streamIds;
                string extension;
    
                var sFileNameOnly = "wordtest.doc";
                mineType = MimeMapping.GetMimeMapping(sFileNameOnly);
    
                // Export the RDLC Report to Byte Array.
                 Byte[] reportBytes = 
                    ReportViewer1.LocalReport.Render("WORD",
                                                      null,
                                                      out mineType,
                                                      out Encoding,
                                                      out extension,
                                                      out streamIds,
                                                      out warnings);
    
                Response.ContentType = mineType;
                Response.AppendHeader("Content-Disposition", "inline; filename=" + sFileNameOnly);
                Response.BinaryWrite(reportBytes);
                Response.End();
    
    

    Now, I could (should) look up how to export as docx, the newer word format, but the above does export the report, and then downloads to the client computer from a browser.

    Edit: just replace WORD with WORDOPENXML if you want the download/export to be docx in place of the older ".doc" binary word file format.

    0 comments No comments

  2. John In 0 Reputation points
    2023-06-19T10:23:03.68+00:00

    Greetings!

    Dear Antony Durai,

    Here's a detailed solution to your problem: If you are experiencing issues with the download option in ReportViewer WebForms, where the download functionality is not working as expected, you can try the following troubleshooting steps:

    1. Check ReportViewer Version: Ensure that you are using the latest version of ReportViewer WebForms. Sometimes, older versions may have compatibility issues or lack certain features. Updating to the latest version can help resolve any known issues.
    2. Verify Browser Compatibility: Confirm that the browser you are using is compatible with ReportViewer WebForms. Different browsers may have varying levels of support for ReportViewer functionality. Try accessing the report in different browsers to see if the issue persists or if it is specific to a particular browser.
    3. Check Download Permissions: Ensure that the user accessing the report has the necessary permissions to download files from the ReportViewer. Check the server-side code or report configuration to ensure that the download option is enabled and accessible for the user.
    4. Examine File Formats: Check the file format of the report you are trying to download. ReportViewer WebForms supports various file formats such as PDF, Excel, Word, etc. If you are encountering issues with a specific format, try downloading the report in a different format to see if it works. Additionally, verify that the required file format rendering extensions are properly installed on the server.
    5. Debug Error Messages: If you are encountering error messages when attempting to download the report, examine the error details to gain insight into the underlying issue. The error messages can help pinpoint the problem and guide you towards a resolution. Look for any specific error codes or descriptions that can assist in troubleshooting.
    6. Community and Documentation: Seek help from the community forums or developer communities specific to the ReportViewer WebForms. Many developers may have encountered similar issues and can provide guidance or solutions. Additionally, consult the official documentation or support resources for ReportViewer WebForms for any specific troubleshooting steps or updates. For more details on this problem, follow this website and check out the solution.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.