Anuja Bhargava

Anuja Bhargava

  • NA
  • 1
  • 4.4k

Unable to open Excel sheet โ€“ Asp.net C#

Oct 15 2012 9:41 AM

I am trying to open excel sheet in C#, for this am fetching base64 data from database and assigning it to byte array.

However, it is not working. It looks like it just stops streaming the data so all I get is a blank IE page. This is happening when I click on Open button of  windows popup, but when I click the save button this code works as it save the file and also file is opening properly from saved location.

Code used is as below :

                       byte[] byteFile;

             DataSet ds = new DataSet();

             ds = ExportDocument(docType);

             byteFile = Convert.FromBase64String(ds.Tables[0].Rows[0]["FileContent"].ToString());

             Response.Clear();

                       Response.AddHeader("Content-Disposition", "inline; filename= ABC.xls");

             Response.ContentType = "application/vnd.ms-excel";

                       Response.OutputStream.Write(byteFile, 0, byteFile.Length);

             Response.End();

 

P.S  File size is around 4 MB.

Please let me know 
how to solve this issue?
Thanks in advance!


Answers (1)