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 .
telliot79Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

anarki_jimbelSenior DeveloperCommented:
If I understand the problem properly, everything is right.

You attach a text (html) content but indicate that this content is MS Excel file. But this is not correct!
The code Attachment.CreateAttachmentFromString(html.ToString(), ct)  does not generate an excel file.
See https://msdn.microsoft.com/en-us/library/ms144617(v=vs.110).aspx
Of course when you are trying to open this text as an xls file it produces an error.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
telliot79Author Commented:
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.)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.