0

I have developed a responsive website in asp.net using C# and it's working fine in Desktop as well as Mobile, all funcationality working fine.

But in Nokia Lumia 920 when I download Excel it is downloaded it but not opening in Phone. It throws error like Incorrect format

I have used the below mentioned code for downloading Excel

Response.AddHeader("content-disposition", "attachment;filename=" + ExcelFileName + ".xlsx");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringBuilder build = new StringBuilder();
//buid contain data
Response.Output.Write(build.ToString());
Response.Flush();
Response.End();

What can be the solution?

Abbas
  • 14,186
  • 6
  • 41
  • 72
Dhaval Patel
  • 7,471
  • 6
  • 37
  • 70
  • Try to change the ContentType to "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" . Also, are you sure you need that header "content-disposition" ? Usually that's for email attachments – Stefano Driussi Sep 02 '14 at 10:27
  • @StefanoDriussi:Nop it's still give me same error – Dhaval Patel Sep 02 '14 at 10:38

1 Answers1

0

There is nothing wrong with the phone, problem is in your code. You are serving html and in response headers set that response is xlsx, so really it is incorrect format, it's not xlsx as phone expects.

On desktop this works only becouse desktop excel knows how to use html tables and show it as excell sheet, but AFAIK Excel 2007 and newer versions warns the user that data is in the incorrect format.

Only solution is to use some excel library and generate true excel file. For example use EPPlus it's simple and it's works OK on server.

Here is the example of exporting ADO.NET DataTable to excel sheet and serving it to the client :

https://stackoverflow.com/a/9569827/351383

Community
  • 1
  • 1
Antonio Bakula
  • 20,445
  • 6
  • 75
  • 102