2
votes

In our organization, we export excel file from SSRS report and attach the excel file in outlook. Also we copy selected part from excel file sheets and paste in outlook mail body.

If we schedule the report in SSRS server and select MHTML option for sending the mail, then all the excel sheet content is included in outlook mail body and mail is sent automatically.

I want that only specified portion of ssrs report is included in mail body (as we do manually copy and paste) and mail sent automatically.

I will appreciate your help.

Thanks :-)

1
Can you edit the SSRS report? Are you trying to integrate data? Is this cut and paste process required to populate a database somewhere? - Nick.McDermaid
so you want the one part as mhtml and also an excel attachment in the same subscription email? - KrazzyNefarious
@Nick.McDermaid yes I can edit SSRS report. I just want that the only specified tablix of SSRS report comes in email body of outlook. - user1772390
@BhupeshC yes I want that only specific tablix of SSRS report comes in email body of outlook. For example. I have TablixA and TablixB. I want only TablixA comes in email body not the whole SSRS report. - user1772390
If you can edit the report then I suggest you add a parameter to the report that allows you to conditionally hide or show Tablix B. When you run the report through email you set this parameter to hide Tablix B. You might want to default the parameter to show Tablix B so existing usage is not affected. It's difficult to process SSRS output after it is rendered. - Nick.McDermaid

1 Answers

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