Download all Zip files from a webpage

Posted on 2012-08-23
Last Modified: 2012-09-06
Need to access the below website and download all the listed Zip files to a local folder on my system.  These files could change so need the program to read current list.

I did find the following code to download a file but I need something to create a list of the zip files on the site.

        private void btn_download_Click(object sender, EventArgs e)
            WebClient webClient = new WebClient();
            webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
            webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
            webClient.DownloadFileAsync(new Uri(""), @"c:\data\DL\");

        private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
            progressBar.Value = e.ProgressPercentage;

        private void Completed(object sender, AsyncCompletedEventArgs e)
            MessageBox.Show("Download completed!");

Open in new window

Question by:kwitcom
    1 Comment
    LVL 74

    Accepted Solution

    I'd say look into the HTML Agility Pack. You can use this tool to download the HTML of the page and extract out all the zip filenames. Then use your WebClient to download the files. For example:

    using (WebClient webClient = new WebClient())
        HtmlDocument doc = new HtmlDocument();
        Uri baseAddress = new Uri("");
        Uri mainPage = new Uri(baseAddress, "taxfiles.html");
        string html = webClient.DownloadString(mainPage.ToString());
        foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
            if (link.InnerText.EndsWith(".zip"))

    Open in new window

    I'm dumping to the Console, but I think you can see how to modify it to download the file. Do note that since the site uses relative URLs, you will need a touch of string manipulation to get the correct URL to pass to the WebClient. This should be relatively straight-forward, though.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    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