c# Mail Service, add LocalReport to Attachment, LocalReport.Render not working

23 Views Asked by At

I am trying to add LocalReport to mails attachment. When i try to run service in debugMode its not giving any error, But in Services->run, service is not working. When i remove LocalReport.Render row, it s working as a Service.

Is there any problem with use Render in a Service or should i change my render method?


                        string deviceinfo = "";
                        string[] streamsId;
                        Warning[] warnings;
                        string mimeType = string.Empty;
                        string encoding = string.Empty;
                        string extension = string.Empty;
                        ReportViewer viewer = new ReportViewer();
                        viewer.ProcessingMode = ProcessingMode.Local;
                        viewer.LocalReport.ReportPath = "Report1.rdlc";
                        ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();
                        reportDataSource1.Name = "DataSet1";
                        reportDataSource1.Value = sayimIcerigi;
                        viewer.LocalReport.DataSources.Add(reportDataSource1);

                        var bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding,
                              out extension, out streamsId, out warnings);
                       string filename = "C:\\Users\\gokhan.bozkus\\Desktop\\sendmail\\MailSendService\\MailSendService\\bin\\Debug\\TalepDurumu" + dr["no"] + ".pdf";
                       File.WriteAllBytes(filename, bytes);
                        MailMessage mail1 = new MailMessage();
                        SmtpClient sc1 = new SmtpClient();
                        sc1.Credentials = new System.Net.NetworkCredential("xxxxxxxxxx", "xxxxxxxxxxx");
                        sc1.Port = 587;
                        sc1.Host = "xxxxxxxxx";
                        sc1.EnableSsl = true;
                        mail1.From = new MailAddress("xxxxxxx");
                        if (dr["firmail"].ToString() == "")
                        {
                            mail1.To.Add("xxxxxxxxxxx," + dr["mail"] + "");
                        }
                        else
                        {
                            mail1.To.Add("xxxxxxxx," + dr["firmail"] + "," + dr["mail"] + "");
                        }
                        mail1.Subject = "Talep Bilgilendirme Maili";
                        mail1.IsBodyHtml = true;
                       System.Net.Mail.Attachment attachment11;
                       attachment11 = new System.Net.Mail.Attachment(filename);
                       mail1.Attachments.Add(attachment11);
                        mail1.Body = "xxxxxxxxxxxxxx" ;
                        sc1.Send(mail1);
                        attachment11.Dispose();
0

There are 0 best solutions below