[Last Call] Learn how to a build a cloud-first strategyRegister Now


Open excel file from memorystream

Posted on 2011-05-05
Medium Priority
Last Modified: 2012-05-11
I am storing Excel files in an Oracle database.  The mime type is "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet".  When I try to open the document on my ASP.Net page I get the following error message.  "Excel found unreadable content in 'fileName.xlsx'.  Do you want to recover the contents of this workbook?  If you trust the source of this workbook, click Yes.".  When you click Yes I get the next error message of "Excel cannot open the file 'fileName.xlsx' because the file format or file extension is not valid.  Verify that the file has not been corrupted and that the file extension matched the format of the file.  This is a very basic Excel file that only has the date in cell 1, there are no pivot tables or anything else.  Here is the code that I am using to open the file.   If I save the file as Excel 97-2000 format it works fine.  But in Excel 2007 and 2010 it does not work.
	Response.AppendHeader("content-disposition", String.Format("attachment, filename={0}", "fileName"));

	Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

	Response.Buffer = true;
	Response.Charset = "";

	byte[] myFile = FileData;

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

catch (Exception ex)
	throw new Exception(ex.Message);


Open in new window

Question by:scott0912
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35701931
Why are you calling a write operation twice?

Accepted Solution

scott0912 earned 0 total points
ID: 35701937
I found the problem.  I was doing a BinaryWrite for PDF files and once I removed that then it started to work.
LVL 50
ID: 35913499
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a serious pitfall that can happen when deleting shapes using VBA.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question