Download multiple files in one request

Posted on 2011-04-28
Last Modified: 2013-12-16
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

Question by:MrB8r
    LVL 25

    Accepted Solution

    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.
    LVL 10

    Expert Comment

    by:John Claes
    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

    Author Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Suggested Solutions

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now