or
[HttpPost]
[Route(
"api/supportingreports/email/{reportName}"
)]
public
bool
SendReportViaEmail(
string
reportName)
{
// TODO verify user access to report
try
{
var reportProcessor =
new
ReportProcessor();
var report =
new
Report {DocumentName = HttpContext.Current.Server.MapPath(
string
.Format(
"{0}{1}.trdx"
, FileUtility.ReportPath, reportName))};
var instanceReportSource =
new
InstanceReportSource {ReportDocument = report};
instanceReportSource.Parameters.Add(
new
Parameter(
"userId"
, 3));
instanceReportSource.Parameters.Add(
new
Parameter(
"eventId"
, 0));
instanceReportSource.Parameters.Add(
new
Parameter(
"exceptionId"
, 14));
instanceReportSource.Parameters.Add(
new
Parameter(
"employeeId"
, 3860));
var result = reportProcessor.RenderReport(
"PDF"
, instanceReportSource,
new
Hashtable());
var fileName = report.Name +
"."
+ result.Extension;
var path = Path.GetTempPath();
var filePath = Path.Combine(path, fileName);
var mailMessage =
new
MailMessage {From =
new
MailAddress(ConfigurationManager.AppSettings[
"fromAddress"
])};
using
(var fs =
new
FileStream(filePath, FileMode.Create))
{
fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
fs.Seek(0, SeekOrigin.Begin);
var a =
new
Attachment(fs, report.Name +
"."
+ result.Extension);
mailMessage.Attachments.Add(a);
mailMessage.To.Add(
new
MailAddress(
"cbohatka@aztekweb.com"
));
mailMessage.Subject =
"TEST"
;
var smtpClient =
new
SmtpClient();
smtpClient.Send(mailMessage);
}
}
catch
(Exception ex)
{
Debug.WriteLine(ex.Message);
throw
;
}
return
true
;
// dummy return
}
void
ReportToDefault(Report report)
{
if
(report ==
null
)
return
;
System.Drawing.Printing.PrintController standardPrintController =
new
System.Drawing.Printing.StandardPrintController();
Telerik.Reporting.Processing.ReportProcessor reportProcessor
=
new
Telerik.Reporting.Processing.ReportProcessor();
reportProcessor.PrintController = standardPrintController;
try
{
reportProcessor.PrintReport(report, Properties.Settings.Default.defaultPrinter);
}
catch
(Exception ex) { MessageBox.Show(ex.Message); }
}