Download multiple files in one request

I got a list of files to download from a server.
Download links look like:


When I click the above link, it opens up the File Dialog to allow me to open or save the file.

I need to iterate through a list of such recordingid's and download all files in a one go (as a single zipped file or multiple files).

I'm looking for something like:

List<string> recordings = GetListOfRecordingIDs();

foreach (string recID in recordings)
     String strUrl = "http://my-server/record/download.cgi?recordingid=" + recID;
     //Code to download the list of files(strUrl) here;

Open in new window

Who is Participating?
Luis PérezConnect With a Mentor Software Architect in .NetCommented:
Here is the code to programatically download a file based on its URL.

HttpWebRequest request;
HttpWebResponse response = null;
   request = (HttpWebRequest)WebRequest.Create(URL);
   request.Timeout = 10000;
   request.AllowWriteStreamBuffering = false;
   response = (HttpWebResponse)request.GetResponse();
   Stream s = response.GetResponseStream();
   //Write to disk
   FileStream fs = new FileStream(SAVE_PATH, FileMode.Create);
   byte[] read = new byte[256];
   int count = s.Read(read, 0, read.Length);
   while (count > 0)
      fs.Write(read, 0, count);
      count = s.Read(read, 0, read.Length);
   //Close everything
catch (System.Net.WebException)
   if (response != null)

It uses the System.Net and System.IO namespaces.

Hope that helps.
John ClaesSenior .Net Consultant & Technical AnalistCommented:
i would suggest the folowing ....

You have The List of FileId's you want to download.
I would suggest the following .

Demand the safe location at the user (only use the directoryName)
Loop through the FileId's
*   Call the Method of RolandDeschain
    *   SAVE_PATH = the retreived directoryName  + the FileName for the current FileId
    *   URL = Your URL using the current FileId

poor beggar
MrB8rAuthor Commented:
Sorry I was too busy to try this until today.

Thanks RolandDeschain and poor_begger.
I have used RolandDesichain method and looped through as per poor_begger's note and got it all done.
All Courses

From novice to tech pro — start learning today.