Problem opening Excel from Response.WriteFile output stream

J

Jonathan

Hi everyone,
I'm having an issue with my Excel streaming. I run my procedure and if
I "Save As" when the dialog opens and then open the file I generate,
it's perfect. Also, if I choose "Open" when Excel is already running,
it's perfect.
If I click "Open" but Excel isn't running, I get an error message:
'C:\...snip...\Temporary Internet
Files\Content.IE5\CPW1639P\export090220061230 [1].xls' could not be
found. Check the spelling of the file name, and verify that the
location is correct.
If you are trying to open the file from your list of most recently used
files on the File menu, make sure that the file has not been renamed,
moved, or deleted.

The file is not, in fact, there in the folder.
I tried generating a more unique filename so that it wouldn't keep
using export.xls and using the [1] all the time, but that did nothing.

My output stream is constructed with:
Response.Cache.SetExpires(DateTime.Now.AddSeconds(1));
Response.Charset = "";
Response.Buffer = true;
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
string datetimeid = DateTime.Now.ToString("MMddyyyyHHmm");
Response.AppendHeader("Content-Disposition", "attachment;
filename=export" + datetimeid + " .xls");
Response.WriteFile(fname); // fname is the file constructed earlier in
the process
Response.Flush();
Response.End();

So why can I save the file and open it up, but I can't open it up right
from the Open/Save As dialog?

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top