Reputation: 705
I'm creating an Excel file (xlsx) from C# using OpenXML.
When I create a xlsx file and I open, it has no error.
When I try to attach that file on an e-mail and send it, Excel returns the message "found unreadable content" opening the attached file, with Yes/No button to continue.
Clicking on Yes the file is opened correctly.
This is my code to attach an xlsx file:
byte[] bt = functionToCreateXlsxfile();
MailMessage message = new MailMessage();
System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(
new MemoryStream(bt),
"myfile.xlsx",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
attach.ContentDisposition.CreationDate = DateTime.Now;
attach.ContentDisposition.ModificationDate = DateTime.Now;
attach.ContentDisposition.Inline = false;
attach.ContentDisposition.Size = bt.Length;
message.Attachments.Add(attach);
Upvotes: 2
Views: 12688
Reputation: 331
Trying having the user save the excel document to their local machine and then open it. If errors still persist, instead of creating a .xlsx file from your code, just create a .xls and see if the same issue occurs.
If both methods above don't help, these two links may help
I don't think that this issue is related to your code at all. It seems like this is a common excel error that many people are getting.
Also, give this tool a whirl and see if it may help.
Upvotes: 3