Problem to response the xls File to the Client

Mar 19, 2014 at 11:49 PM
Hi there, my problem is the file is not writing to the client side nothing happening

my code is above:
            //Save the Excel spreadsheet to a MemoryStream and return it to the client
            using (var exportData = new MemoryStream())
            {
                try
                {
                    hssfworkbook.Write(exportData);
                    string saveAsFileName = string.Format("ObrasNuevas-{0:d}.xls", DateTime.Now).Replace("/", "-");
                    Context.Response.ContentType = "application/vnd.ms-excel";
                    Context.Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", saveAsFileName));
                    Context.Response.Clear();
                    Context.Response.BinaryWrite(exportData.GetBuffer());
                    Context.ApplicationInstance.CompleteRequest();
                    //Context.Response.End();
                }
                catch (Exception ex)
                {
                    Context.Response.Write(ex.Message);
                }



            }
my server is Windows 2003 , only work with chrome but with ie i cant get the xls file


thanks
I really Appreciate your comments.
Mar 25, 2014 at 7:39 PM
First off, I just wanted to point out that your issue is not with NPOI.

Next, looking at your code, I believe you may need to add the content size to the response header.

Try adding the following immediately after the addition of the Content-Disposition to the header:
Context.Response.AddHeader("Content-Length", exportData.Length.ToString());
If that doesn't solve your problem, try changing the Content-Type from application/vnd.ms-excel to application/octet-stream.

-MindCore
Marked as answer by tonyqus on 4/12/2014 at 1:58 PM
Mar 28, 2014 at 4:59 PM
Thanks for your time MindCore, I find that my problem is not with NPOI, my problem was an error in IE thant does not unsderstand the JSON i have to add a JSCRIPT File the implement the JSON the File "minjson2.js" that implemente the methods JSON.stringify(Objeto) and other that suppose are native in the navigator.

Sorry my english is not very well thanks for your time to advice.