File download

  1. #1

    File download

    hi,

    i have download the file from particulat location. i wrote the code using asp.net button click event, its working fine. but coolite button click event , the same code does not working. what is the problem. i got error Status code: 200 Status text: BADRESPONSE: Syntax error.


    
    
    
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    
    
    <ext:button ID="Button2" runat="server" AutoPostBack="false"> 
    
    
    <AjaxEvents>
    
    
    <Click OnEvent="Button1_Click1"> 
    
    
    </Click>
    
    
    </AjaxEvents> 
    
    
    
    
    
    </ext:button> 
    
    
    protected void Button1_Click(object sender, EventArgs e)
    
    
    {
    
    
    FileInfo file = new FileInfo(Server.MapPath("Chap0101.pdf"));
    
    
    if (file.Exists)
    
    
    {
    
    
    Response.Clear();
    
    
    Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
    
    
    Response.AddHeader("Content-Length", file.Length.ToString());
    
    
    // Response.ContentType = "application/octet-stream";
    
    
    Response.ContentType = "application/pdf";
    
    
    Response.WriteFile(file.FullName);
    
    
    Response.End();
    
    
    }
    
    
    else
    
    
    {
    
    
    }
    
    
     
    
    
     
    
    
    }
    
    
    protected void Button1_Click1(object sender, EventArgs e)
    
    
    {
    
    
    FileInfo file = new FileInfo(Server.MapPath("Chap0101.pdf"));
    
    
    if (file.Exists)
    
    
    {
    
    
    Response.Clear();
    
    
    Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
    
    
    Response.AddHeader("Content-Length", file.Length.ToString());
    
    
     
    
    
    Response.ContentType = "application/pdf";
    
    
    Response.WriteFile(file.FullName);
    
    
    Response.End();
    
    
    }
    
    
    else
    
    
    {
    
    
    }
    
    
    }
  2. #2

    RE: File download

    Hi,

    At this moment you can't download file during AjaxEvent because it brakes AjaxEvent. But functionality which you try to implement can be useful therefore I'll try to resolve it today/tomorrow


Similar Threads

  1. Download txt file problem
    By boris in forum 1.x Help
    Replies: 0
    Last Post: Jun 06, 2011, 12:19 PM
  2. [CLOSED] [1.0] MVC Download file
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Aug 02, 2010, 11:10 AM
  3. [CLOSED] Download a file in an MVC app
    By Stefanaccio in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 02, 2010, 9:01 PM
  4. [CLOSED] [1.0] File download in MVC
    By tdracz in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 23, 2009, 4:43 PM
  5. Download file in MVC project
    By danni in forum 1.x Help
    Replies: 0
    Last Post: Aug 10, 2009, 7:50 AM

Posting Permissions