Monday, 22 July 2013

downloadfile on button click

Code to download file on button click in asp.net

 protected void Button1_Click(object sender, EventArgs e)
    {
        string Filename = MapPath("Test.pdf");
        // This is an important header part that informs the client to download this file.
   Response.AppendHeader("content-disposition", "attachment; filename="+Path.GetFileName(Filename));
        Response.ContentType = "Application/pdf";
        //Write the file directly to the HTTP content output stream.
        Response.WriteFile(Filename);   

    }

No comments:

Post a Comment