Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when evere i am generating a excel sheet i am getting error

"the file you are trying to open ,"RiskReport.xls" ,is in a different Format than soecified by the file extention. verify that file is not corrupted and is from a trusted source befor opening the file. Do you want to open the file now. "

if i am cliking on YES then only file is open without data if "no" then alll file is open successfully.




C#
byte[] data = new System.Text.ASCIIEncoding().GetBytes(theWorkbook.ToString());

if (format == "Excel")
                    {
                        Byte[] fileContent = manager.GetRiskReportByte(format, orgRecNos, noPendingProposals, isPendingProposals, isDisapprovedProposals, dateFrom, dateTo, minRiskScore, maxRiskScore, dataOnlyValue, riskScoreRecNos, isUnassessed, orderByParam, orderByFlow, isAllRisk);
                        const string fileName = "RiskReportxl" + ".xls";
                        try
                        {
                            response.ContentType = "application/xls";
                            response.AddHeader("content-disposition", "attachment; filename=" + fileName);
                            response.BinaryWrite(fileContent);
                            response.End();


                        }




[edit]SHOUTING removed, overenthusiastic HTML encode fixed - OriginalGriff[/edit]
Posted
Updated 7-Jul-13 21:37pm
v2
Comments
OriginalGriff 8-Jul-13 3:37am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
siddharth629 8-Jul-13 4:29am    
????
OriginalGriff 8-Jul-13 4:35am    
http://en.wikipedia.org/wiki/Etiquette_(technology)
Maciej Los 8-Jul-13 4:55am    
Check the file name! You want to open RiskReport.xls, but in code you are trying to open RiskReportxl.xls. Do you see the difference?
siddharth629 8-Jul-13 5:24am    
thaks sir.
but is does not working same error is appear. when ever i am usng /*theWorkbook.SaveCopyAs(fileName);
theWorkbook.Close(false, fileName, true);
byte[] data = ExportImportUtil.StreamFile(fileName);
File.Delete(fileName);*/


instead of byte[] data = new System.Text.ASCIIEncoding().GetBytes(theWorkbook.ToString());

then there is no error .

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