Sending xls file from Server to Client via asp.net

Discussion in 'ASP .Net' started by Lars Netzel, Nov 10, 2005.

  1. Lars Netzel

    Lars Netzel Guest

    I have an XLS file that I try to send to the webclient via ASP.NET. When
    sending I use this code...
    Response.ClearContent()

    Response.ClearHeaders()

    Response.ContentType = "application/vnd.ms-excel"

    Response.AddHeader("Content-Disposition", "inline; filename=" &
    ClientFilename & ".xls")

    Response.WriteFile(Filename)

    Response.Flush()

    The Problem:

    When clicking the link that is running this code the "_blank" window that is
    suppoed to show the excel file, closes imediately... it's like.. I click..
    a new window opens and closes right away.. no error messages

    I do the same for a PDF file with the only exception for the contenttype and
    extention of the file name. and that works fine.

    What's the problem you think? why does a PDF work and not the Xls file?

    best regards

    /Lars
     
    Lars Netzel, Nov 10, 2005
    #1
    1. Advertisements

  2. Lars,

    I'm not certain if this will help in your situation or not. I was just
    looking over some code of mine for outputting a datagrid as an excel file so
    it's a little bit different than your code, but I do two things before
    sending the stream to the client that you're not doing:

    1.. '---Clear the characterset
    2.. Response.Charset = ""
    3..
    4.. '---Viewstate must be turned off.
    5.. Me.EnableViewState = False
    Maybe adding this will work.

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
     
    S. Justin Gengo, Nov 10, 2005
    #2
    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.