Last post Jul 02, 2011 12:54 AM by Ashutosh Pathak
Jul 01, 2011 07:52 AM|jurcisinjakub|LINK
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
Jul 01, 2011 03:57 PM|bkotvis|LINK
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.
Jul 02, 2011 12:54 AM|Ashutosh Pathak|LINK
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;
byte bytes = null;
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);
}Now you can send this file as an attachment in mail from asp.net mail classes