Here is My Export code.
public void ExportCSV_Employee(HttpPostedFileBase file )
{
var sb = new System.Text.StringBuilder();
var list = _context.ProductItems.ToList();
foreach (var item in list)
{
sb.AppendFormat("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}\t{12}\t{13}\t{14}\t{15}\t{16}\t{17}\t{18}\t{19}\t{20}\t{21}\t{22}\t{23}\t{24}\t{25}\r", item.ScanCode, item.Name, item.UnitRetail, item.UnitCost, item.DeptName, item.PriceGroup, item.ProductCode, item.Pcode, item.StateTax, item.MaxQty, item.Modified, item.AllowFoodStamps, item.LocalTax, item.Crv, item.MinAge, item.AllowDirectDept, item.IsNegative, item.DeptType, item.ItemCategoryId, item.ProductSubCategory, item.AllowFractionDept, item.BuyDown, item.UpcType, item.OverRide, item.PkgSize, item.Discount);
}
//mail method to send mail
MailMessage mail = new MailMessage();
mail.From = new System.Net.Mail.MailAddress("mymail@gmail.com");
SmtpClient smtp = new SmtpClient();
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("mymail@gmail.com" , "password");
smtp.Host = "smtp.gmail.com";
//recipient address
mail.To.Add(new MailAddress("receiver@gmail.com"));
}
in this way, my mail sending work but I want to attach the date from my database as a start retrieving through StringBuilder. How can I attach my data as a file attachment with email?