[RESOLVED] Response.WriteFile returns the aspx page!
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: [RESOLVED] Response.WriteFile returns the aspx page!

  1. #1
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    [RESOLVED] Response.WriteFile returns the aspx page!

    Hi all,

    My code generates an excel file and should be sending it to the user for download. Instead, the user is getting the .aspx page as an .xls file! o.O

    Can someone shed some light on this? Many thanks in advance

    Code:
    Response.ContentType = "application/x-msexcel";
    
    System.IO.FileInfo fileToDownload = new System.IO.FileInfo(filename.ToString());
    System.String disHeader = "Attachment; Filename=\"" + fileToDownload.Name + "\"";
    Response.AppendHeader("Content-Disposition", disHeader);
    
    Response.Flush();
    Response.WriteFile(fileToDownload.FullName);
    It's not a bug, it's a feature!

  2. #2
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    Re: Response.WriteFile returns the aspx page!

    I seem to have solved this

    The problem: the Excel process was still running when I attempted to transmit the file. This triggered an exception which somehow lead to the aspx file being transmitted O.o

    Hope this helps someone else in this situation
    Last edited by foamy; January 21st, 2011 at 06:47 AM.
    It's not a bug, it's a feature!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center