CSV File Download from an ASP.NET page issue

Discussion in 'ASP .Net' started by Guest, Dec 17, 2004.

  1. Guest

    Guest Guest

    I'm using the following code to stream a CSV file download to the client
    browser -

    HttpContext.Current.Response.Buffer = true;
    HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
    HttpContext.Current.Response.AddHeader( "content-disposition","attachment;
    filename=" + filename );

    (where <filename> is equal to the filename, eg test.csv; and <bytes> is
    equal to a bytearray of the actual CSV data)

    Everything is fine and dandy except for one tiny glitch - The "File
    Download" dialog box (the one that asks Save, Open, Cancel, More Info)
    appears twice in succession when you click on Open. If you click on Save,
    the CSV file is saved ok to the clients machine then the user is prompted to
    Open the file. If you simply click on Open, the same dialog box immidiately
    reappers and you have to click on Open again to display the file in Excel.
    Guest, Dec 17, 2004
    1. Advertisements

  2. Guest

    Guest Guest

    I've just been trying to solve the same problem when downloading text files
    to the client. However, after a couple of hours scouring the net, the
    following URL discusses the same problem which appears to be a bug in certain
    IE browsers.

    Apparently 'longhorn' fixes this.

    The article discusses the fact that this works if the method used is GET as
    opposed to POST. I have still not found any documentation from Microsoft
    detailing this problem - can anyone else enlighten us?


    Thanks, Claire-Louise
    Guest, Dec 22, 2004
    1. Advertisements

  3. Guest


    May 26, 2012
    Likes Received:
    This is what works for me, i know this is an old post but i found it, someone else will too.

    Response.Buffer = true;
    Response.ContentType = "text/csv";
    Response.AddHeader("Content-Disposition", "attachment; filename=" + CSVFile);
    workabyte, May 26, 2012
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.