SoFunction
Updated on 2025-03-06

C# implements batch download of pictures to local sample code

1. Overview

Batch downloading of pictures is a requirement that we often encounter in daily development. Recently, we need to batch download pictures to the local area in our work. First, we generate all link addresses through Excel splicing, and then we think of batch downloading by downloading software. But when I think about taking time to find, install and research software, it is better to write it yourself faster.

The following is the console program code developed using C# to read each line of the address string in the text file by looping to perform downloading and saving it to a local folder.

I won't say much below, let's take a look at the detailed introduction

2. C# instance code

//using System;
//using ;
//using ;
//using ;
//--------------------------------------------

static void Main(string[] args)
{
 //StreamReader reads int count = 0;
 using (Stream readerStream = new FileStream(@"d:\", ))
 using (StreamReader reader = new StreamReader(readerStream, Encoding.UTF8))
 using (WebClient client = new WebClient())
 {
  string line;
  while ((line = ()) != null)
  {
   count++;
   (line + " " + count);
   Uri uri = new Uri(line);
   if (uri!=null)
   {
    string filename = ();
    (uri, @"c:\pictures\"+filename);
    ("document:"+filename+"Downloaded successfully!" + "Count:"+ count);
   }
   else
   {
    ("path:" + line + "Not download address! Failed serial number:"+count );
   }
   
  }
 }

 ("Download is complete!");
 ();
}

3. Reference articles

How to download image from url

Summarize

The above is the entire content of this article. I hope that the content of this article has certain reference value for everyone's study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.