Displaying Save File Dialog in Asp.net web page

I have a ASP.net page which writes a file to the local disk.

I want to present the user a Save File dialog box and allow him to set the path to the folder.

I know code like below can be used;

Response.Clear();
Response.ContentType = "text/csv";
Response.AddHeader( "Content-Disposition", "attachment;filename=\"report.csv\"" );
// write your CSV data to Response.OutputStream here
Response.End();

But it fixes filepath.

I need to capture the filepath that the user selects.
Is that possible in ASP.net?

Thanks.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

it does not work like that from a web page, you have to initiate the download suggestiong a target file name then the user can override your suggested file name and select any folder or filename he likes and your content will be saved in that location.

you do nothing with a local path which only makes sense on the client machine on the server side of ASP.NET application.

Solution 2

I need to capture the filepath that the user selects. Is that possible

No. Your web server presents a file to the client, where the client has the option to save this file.

In what way would the path the client saves this file be interesting to the server?

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply