0

I am trying to download a file from a URL and I want to have a Popup where I can decide where to save the file on my pc. I know how to save it to a setlocation but that's not what I want.

WebClient webClient = new WebClient();
webClient.DownloadFileAsync(new Uri("URL"), @"d:\location");

So I get that this is how I download it so a set location but I need to be able to save it to a location of choice with the usual popup you normally get when you download anything.

To give more sight into this I have 2 radiobuttonlists in which the user can check what topics he wants then he can choose from a dropdownlist which file he wants to download and then he click on a downloadbutton which should trigger the download of that file.

BlackPanic
  • 35
  • 8
  • Not completely sure what you're after - does [ASP.net File Download from Server](http://stackoverflow.com/questions/18477398/asp-net-file-download-from-server) help? – stuartd Jun 30 '16 at 09:21
  • 1
    Is this a desktop app or a asp.net website? Makes a lot of difference. – HaukurHaf Jun 30 '16 at 09:21
  • What are you trying to do? If you want to download something on the server side then you will most likely not have a UI and therefore not show a pop up. If you want the user to download something then you don't need to do anything in C#. Just put a HTML link pointing to the download link and the browser will automatically show a pop up. – dustinmoris Jun 30 '16 at 09:22
  • it's a website sorry if I missed on that. I have a webserver with data stored and the user should select stuff he wants to download and then be able to say where to save it to. I just need to know how the downloading part works here. – BlackPanic Jun 30 '16 at 09:24
  • What you're doing here downloads the file **on the server**, it does not makes the client download the file. – Irwene Jun 30 '16 at 09:48

2 Answers2

0

Use DownloadFileAsync and listen to DownloadFileFinished. First download it to temp file and at event DownloadFileFinished, show popup and ask where to save. Then just copy the file from temp file to the filename from user. -or- Show SaveFileDialog before you start DownloadFileAsync.

0

Talking about a desktop app you can use SaveFileDialog.

The msdn code example:

    private void button1_Click(object sender, System.EventArgs e)
 {
     Stream myStream ;
     SaveFileDialog saveFileDialog1 = new SaveFileDialog();

     saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"  ;
     saveFileDialog1.FilterIndex = 2 ;
     saveFileDialog1.RestoreDirectory = true ;

     if(saveFileDialog1.ShowDialog() == DialogResult.OK)
     {
         if((myStream = saveFileDialog1.OpenFile()) != null)
         {
             // Code to write the stream goes here.
             myStream.Close();
         }
     }
 }
pijemcolu
  • 2,257
  • 22
  • 36