如何在outlook中嵌入ssrs报表?
how to embed ssrs report in outlook?
在我们的组织中,我们从 SSRS 报告中导出 excel 文件并在 outlook 中附加 excel 文件。我们还从 excel 文件 sheet 中复制 selected 部分并粘贴到 outlook 邮件正文中。
如果我们在 SSRS 服务器中安排报告并使用 select MHTML 选项发送邮件,那么所有 excel sheet 内容都包含在 outlook 邮件正文中并发送邮件自动。
我希望邮件正文中只包含 ssrs 报告的指定部分(因为我们手动复制和粘贴)并自动发送邮件。
非常感谢你的帮助。
谢谢 :-)
string reportName = Your Report Name;
Warning[] warnings;
string[] streamIds;
string encoding = string.Empty;
string extension = string.Empty;
string mimeType = string.Empty;
// Setup the report viewer object and get the array of bytes
var rptViewer = new ReportViewer();
string urlReportServer = ReportServer Path;
rptViewer.ProcessingMode = ProcessingMode.Remote; // ProcessingMode will be Either Remote or Local
rptViewer.ServerReport.ReportServerUrl = new Uri(urlReportServer); //Set the ReportServer Url
string folderName = FolderName;
rptViewer.ServerReport.ReportPath = folderName + reportName; //Passing the Report Path
//Creating an ArrayList for combine the Parameters which will be passed into SSRS Report
var reportParam = param1;
ReportParameter[] param = new ReportParameter[reportParam.Count];
for (int k = 0; k < reportParam.Count; k++)
{
param[k] = (ReportParameter)reportParam[k];
}
// pass crendentitilas
string userName, password, domain;
userName = SSRSUserName;
password = SSRS Password;
domain = SSRS User Domain;
IReportServerCredentials irsc = new BLL.Reports.CustomReportCredentials(userName, password, domain);
rptViewer.ServerReport.ReportServerCredentials = irsc;
//pass parmeters to report
rptViewer.ServerReport.SetParameters(param); //Set Report Parameters
rptViewer.ServerReport.Refresh();
byte[] bytes = rptViewer.ServerReport.Render("HTML4.0", null, out mimeType, out encoding, out extension,
out streamIds, out warnings);
string reportasHTML= Encoding.ASCII.GetString(bytes);
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(SenderID, SenderPassword)
};
using (var message = new MailMessage(Email ID, Email ID)
{
Subject = "test",
Body = reportasHTML,
IsBodyHtml =true
})
{
smtp.Send(message);
}
在我们的组织中,我们从 SSRS 报告中导出 excel 文件并在 outlook 中附加 excel 文件。我们还从 excel 文件 sheet 中复制 selected 部分并粘贴到 outlook 邮件正文中。
如果我们在 SSRS 服务器中安排报告并使用 select MHTML 选项发送邮件,那么所有 excel sheet 内容都包含在 outlook 邮件正文中并发送邮件自动。
我希望邮件正文中只包含 ssrs 报告的指定部分(因为我们手动复制和粘贴)并自动发送邮件。
非常感谢你的帮助。
谢谢 :-)
string reportName = Your Report Name;
Warning[] warnings;
string[] streamIds;
string encoding = string.Empty;
string extension = string.Empty;
string mimeType = string.Empty;
// Setup the report viewer object and get the array of bytes
var rptViewer = new ReportViewer();
string urlReportServer = ReportServer Path;
rptViewer.ProcessingMode = ProcessingMode.Remote; // ProcessingMode will be Either Remote or Local
rptViewer.ServerReport.ReportServerUrl = new Uri(urlReportServer); //Set the ReportServer Url
string folderName = FolderName;
rptViewer.ServerReport.ReportPath = folderName + reportName; //Passing the Report Path
//Creating an ArrayList for combine the Parameters which will be passed into SSRS Report
var reportParam = param1;
ReportParameter[] param = new ReportParameter[reportParam.Count];
for (int k = 0; k < reportParam.Count; k++)
{
param[k] = (ReportParameter)reportParam[k];
}
// pass crendentitilas
string userName, password, domain;
userName = SSRSUserName;
password = SSRS Password;
domain = SSRS User Domain;
IReportServerCredentials irsc = new BLL.Reports.CustomReportCredentials(userName, password, domain);
rptViewer.ServerReport.ReportServerCredentials = irsc;
//pass parmeters to report
rptViewer.ServerReport.SetParameters(param); //Set Report Parameters
rptViewer.ServerReport.Refresh();
byte[] bytes = rptViewer.ServerReport.Render("HTML4.0", null, out mimeType, out encoding, out extension,
out streamIds, out warnings);
string reportasHTML= Encoding.ASCII.GetString(bytes);
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(SenderID, SenderPassword)
};
using (var message = new MailMessage(Email ID, Email ID)
{
Subject = "test",
Body = reportasHTML,
IsBodyHtml =true
})
{
smtp.Send(message);
}