File download dialog

  • Thread starter Thread starter John Spiegel
  • Start date Start date
J

John Spiegel

Hi all,

How does one allow a user to download a file WITH selecting where it should
be downloaded to on their machine? Also, when using the WebClient.Download
method, will the destination path written in Windows format (backslashes,
etc.) translate across client platforms? Is there a better way?

WebClient wc = new WebClient();
wc.DownloadFile(Server.MapPath(@"Downloads\MyFile.pdf"),
@"C:\Temp\TheirFile.pdf");

TIA,

John
 
John,

The easiest way to do what you are asking is to just create a link on the
page pointing to the file to download. (e.g. <a
href="Downloads/MyFile.pdf">Download MyFile.pdf</a>)

A link such as this will open a dialog box which will allow a user to open
or save the file. If they choose save then a dialog box allowing them to
choose where to save the file will open.

Since in your example you are using a .pdf file you should also know that,
depending on the way a user's adobe acrobat reader program is set up the
file may open in the browser window automatically. However, if they choose
file - save from the menu they will be able to save the downloaded file
wherever they want on their drive.

I hope this helps.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
Sheesh. So simple, but I couldn't see the forest through the trees!
Thanks!

- John

Please note: I am not as irretrievably stupid as some of my questions might
make me appear.
 
Back
Top