Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all i have a problem when i export a datatale to excel. When i open the file Excel says, "The file you are trying to open is in a different format than specified by the file extension. Verify the file is not corrupted and is from a trusted source before opening the file."...if i click yes the file does open properly but is there any way to stop this message from appearing?


What I have tried:

HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=TestingReports.xls")
Posted
Updated 27-Apr-21 12:29pm

Quote:
if i click yes the file does open properly but is there any way to stop this message from appearing?

Yes, there is away.
Either you make the contain really xls, either name correctly the file.
When you name a file .xls, excel expect the contain of the file to be encoded in a specific way. if it is not, excel complain with the message you get.
Quote:
i have a problem when i export a datatale to excel.

Anything depend on how your data is exported, the most common file format is some kind of text file like csv format, but without detail on the command used or a sample of the contain, it is impossible to tell further.
 
Share this answer
 
Once you get it successfully opened, use Save or Save As to save a copy of it in .xlsx format. That copy won't give you the warning.

If it's your program that's creating the exported file, and you want the recipient not to get that message, then follow the Patrice's suggestion: Make the name match the format. If it's a comma-separated value (CSV) test file, then use a .csv suffix on the file name when you create it.

If you're getting data from some other application, like a database program or a remote website, then you usually get to pick a name when you save the exported file. In that case, don't just use .xls or .xlsx as the suffix because you intend to open it with Excel. Pick the suffix that matches the format of the file itself.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900