I have a String variable (in C#) that contain the full path of PDF file on my server (like that "~/doc/help.pdf").
I want that in click on button, this file will download to the client computer.
I created a button and made onClick event in C#. Now, which code should I write to do that?
Upload the file using file upload control and click on the Upload button. The uploaded file is displayed in the GridView. Next click on the link button to download the files.
Users can either left-click a download link to download the file or right-click the link to choose “ Save Link As ” in the context menu and save the file.
I think you are looking for something like this.
private void Button1_click(object sender, System.EventArgs e)
{
Response.ContentType = "Application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=help.pdf");
Response.TransmitFile(Server.MapPath("~/doc/help.pdf"));
Response.End();
}
Try this code on your btn_Click
:
Response.Redirect("~/doc/link.pdf");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With