How to send excel attachment mail which is converted from datatable without saving to system in asp.net
-
hi i have result in datatable and i converted to excel using streamwriter. Now i dont want save to computer and then send mail by using that path. Is there any other method that i can send that excel without saving to system in c#. If anybody knows, please reply me. Thanks in advance.
-
hi i have result in datatable and i converted to excel using streamwriter. Now i dont want save to computer and then send mail by using that path. Is there any other method that i can send that excel without saving to system in c#. If anybody knows, please reply me. Thanks in advance.
Try using a MemoryStream[^] to store the Excel file, and pass that stream to the Attachment constructor[^].
var ms = new MemoryStream();
using (var sw = new StreamWriter(ms))
{
RenderExcelAttachment(sw);
}var attachment = new Attachment(ms, "data.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
message.Attachments.Add(attachment);
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer