Problem opening Excel from Response.WriteFile output stream

Discussion in 'ASP .Net' started by Jonathan, Sep 20, 2006.

  1. Jonathan

    Jonathan Guest

    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!
    Jonathan, Sep 20, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Earl Teigrob
    Replies:
    0
    Views:
    898
    Earl Teigrob
    Jan 20, 2004
  2. Ryan Pedersen
    Replies:
    1
    Views:
    2,165
    Daniel Fisher\(lennybacon\)
    Jul 12, 2005
  3. =?Utf-8?B?ZG90bmV0dGVzdGVy?=

    Response.writefile (filename) ?? problem with filesize

    =?Utf-8?B?ZG90bmV0dGVzdGVy?=, Aug 16, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    488
    Buddy Ackerman
    Aug 16, 2005
  4. John
    Replies:
    1
    Views:
    372
    Alexey Smirnov
    May 21, 2010
  5. fniles
    Replies:
    0
    Views:
    256
    fniles
    Apr 26, 2009
Loading...

Share This Page