I followed your below link
in which pdf is being sent and opened, but when i convert it to excel, then excel file is not getting open in email attachment
con.Open();
SqlCommand cmd = new SqlCommand("SP_Employee_Day_Status", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlCommand cmd1 = new SqlCommand("SP_Get_Current_Attendance", con);
cmd1.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@DateFrom", txtDateFrom.Text);
cmd.Parameters.AddWithValue("@DateTo", txtDateTo.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
ReportDataSource rds = new ReportDataSource();
rds.Name = "DSDay";
rds.Value = ds.Tables[0];
ReportDataSource rds1 = new ReportDataSource();
rds1.Name = "DStime";
rds1.Value = ds1.Tables[0];
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.ReportPath = "daystats.rdlc";
ReportViewer1.LocalReport.DataSources.Add(rds);
ReportViewer1.LocalReport.DataSources.Add(rds1);
ReportViewer1.LocalReport.Refresh();
ReportViewer1.Visible = true;
con.Close();
SendEmail();
}
}
private void SendEmail()
{
using (MailMessage mm = new MailMessage("akhxxxing.com","akhtxx80@gmail.com"))
{
mm.Subject = "RDLC Report PDF example";
mm.Body = "RDLC Report PDF example";
mm.Attachments.Add(new Attachment(ExportReportToPDF(Server.MapPath("~/Excel/"), "Attendance_Status.xlsx")));
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "mail.xxxxxx.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential();
NetworkCred.UserName = "axxxxg.com";
NetworkCred.Password = "Dxxsxlxx!@";
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = false;
smtp.Credentials = NetworkCred;
smtp.Port = 25;
smtp.Send(mm);
}
}
private string ExportReportToPDF(string path, string reportName)
{
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string filenameExtension;
byte[] bytes = ReportViewer1.LocalReport.Render("Excel", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);
string filename = path + reportName;
using (var fs = new System.IO.FileStream(filename, System.IO.FileMode.Create))
{
fs.Write(bytes, 0, bytes.Length);
fs.Close();
}
return filename;
}
}