Avatar of telliot79
telliot79
 asked on

the file format and extension don't match if excel attachment

Experts,

I'm sending an excel file as an attachment. the file is generated from an HTML table and when I open it, I receive a warning message stating: "the file format and extension don't match....."

here's my code:

string html = "<table><tr><td>Test</td></tr></table>";

System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("application/vnd.ms-excel");
Attachment a = Attachment.CreateAttachmentFromString(html.ToString(), ct);
a.ContentDisposition.FileName = "Test.xls";
message.Attachments.Add(a);
client.Send(message);

Am I missing something in this snippet?

Thanks in advance for the help,

thanks inadvance for the help .
.NET ProgrammingC#

Avatar of undefined
Last Comment
telliot79

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Dmitry G

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
telliot79

ASKER
thanks anarki_jimbel.

The file does actually open and render correctly. So, what I really should have asked was can excel render html without giving this message. Which the answer appears to be - no. Or at least, I couldn't find a solution after a day of digging. I used openXML to generate the spreadsheet I want which works wonders (and only took me a couple of hours.)
Your help has saved me hundreds of hours of internet surfing.
fblack61