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?
Try this code on your
btn_Click
:With an ASP button:
The logic behind this is here: Client-side click
This will not reload the page and do a post-back, it will just navigate to the PDF which will be displayed in the browser.
Set the button's onclick event to this scriptlet:
To create that server-side:
Where PDFLink is a string property in the code behind:
From here it should be trivial to take the string from the database and render it absolute if need be.
I would suggest the following to be placed into your button click event code.
This will provide the user with a popup to download the file. I've tested it thoroughly and use it in production code.
I think you are looking for something like this.