如何在Outlook中嵌入ssrs报告?

时间:2015-08-20 05:23:43

标签: email reporting-services outlook ssrs-2008-r2

在我们的组织中,我们从SSRS报告中导出excel文件,并在Outlook中附加excel文件。我们还从Excel文件表中复制选定的部分并粘贴到Outlook邮件正文中。

如果我们在SSRS服务器中安排报告并选择MHTML选项发送邮件,那么所有Excel工作表内容都包含在Outlook邮件正文中,邮件会自动发送。

我希望只有指定部分的ssrs报告包含在邮件正文中(因为我们手动复制和粘贴)并自动发送邮件。

感谢您的帮助。

谢谢:-)

1 个答案:

答案 0 :(得分:0)

  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);
                    }