locked
Automate Local Report (ReportViewer 08) to render a report in back-end and email as an attachment RRS feed

  • Question

  • User937573798 posted

    Dear fellows

    I am wondering whether the following using VS08, ReportViewer08 is possible:

    I currently have report viewer in place , all works just fine, user clicks here and there and gets it.

    Now, I've got 10K+ corporate users who I want to simple click SAVE REPORT/AUTOMATE REPORT button for the particular selection of theirs to start receiving them on either daily/weekly/monthly basis w/o a need to come back to the site and go through that pain of filtering through dozens of dropdowns etc.

    So my question is: Can I automate local report to be run in back-end and send out as an attachment?

    I will very much appreciate your thoughts / hints / tips on this matter

    Friday, July 1, 2011 7:52 AM

Answers

  • User2105670541 posted

    YES you can achieve it, please take a look of code below, it will help you to accomplish the same

    //ReportViewer rview = null;
                string mimeType, encoding, extension, deviceInfo;
                string[] streamids;
                Microsoft.Reporting.WinForms.Warning[] warnings;
                byte[] bytes = null;
    
                try
                {
                    string format = "PDF";
                    //Desired format goes here (PDF, Excel, or Image)
                    deviceInfo = "<DeviceInfo>" + "<SimplePageHeaders>True</SimplePageHeaders>" + "</DeviceInfo>";
                    Microsoft.Reporting.WinForms.ReportViewer rview = new Microsoft.Reporting.WinForms.ReportViewer();
                    rview.ServerReport.ReportServerCredentials.NetworkCredentials = new NetworkCredential("ReportServerUser", "password");
                    //Web Address of your report server (ex: http://rserver/reportserver) 
                    rview.ServerReport.ReportServerUrl = new Uri("yourURL");
                    rview.ServerReport.ReportPath = "myReportName";
                     
                    bytes = rview.ServerReport.Render(format, deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings);
    
    now use the bytes ahead in your stream to save it, like below:
    using (FileStream stream = File.OpenWrite("SaveReport.pdf"))
                            {
                                stream.Write(bytes, 0, bytes.Length);
                                stream.Flush();
                                stream.Close();
                            }

    Now you can send this file as an attachment in mail from asp.net mail classes
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 2, 2011 12:54 AM

All replies

  • User-1838067034 posted

    I don't think you can do it with a web site project.  If you are doing a console application or Windows Service I am sure you probably could save peoples preferences and schedule a job to run and send the reports.  However SQL Reporting Services Report Server has all of this built in and I would highly recommend it.

    Friday, July 1, 2011 3:57 PM
  • User2105670541 posted

    YES you can achieve it, please take a look of code below, it will help you to accomplish the same

    //ReportViewer rview = null;
                string mimeType, encoding, extension, deviceInfo;
                string[] streamids;
                Microsoft.Reporting.WinForms.Warning[] warnings;
                byte[] bytes = null;
    
                try
                {
                    string format = "PDF";
                    //Desired format goes here (PDF, Excel, or Image)
                    deviceInfo = "<DeviceInfo>" + "<SimplePageHeaders>True</SimplePageHeaders>" + "</DeviceInfo>";
                    Microsoft.Reporting.WinForms.ReportViewer rview = new Microsoft.Reporting.WinForms.ReportViewer();
                    rview.ServerReport.ReportServerCredentials.NetworkCredentials = new NetworkCredential("ReportServerUser", "password");
                    //Web Address of your report server (ex: http://rserver/reportserver) 
                    rview.ServerReport.ReportServerUrl = new Uri("yourURL");
                    rview.ServerReport.ReportPath = "myReportName";
                     
                    bytes = rview.ServerReport.Render(format, deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings);
    
    now use the bytes ahead in your stream to save it, like below:
    using (FileStream stream = File.OpenWrite("SaveReport.pdf"))
                            {
                                stream.Write(bytes, 0, bytes.Length);
                                stream.Flush();
                                stream.Close();
                            }

    Now you can send this file as an attachment in mail from asp.net mail classes
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 2, 2011 12:54 AM