{"id":75,"date":"2023-09-23T21:00:34","date_gmt":"2023-09-23T15:30:34","guid":{"rendered":"https:\/\/successrouter.com\/tech\/?p=75"},"modified":"2023-09-23T21:00:35","modified_gmt":"2023-09-23T15:30:35","slug":"c-tool-to-download-the-list-of-image-urls","status":"publish","type":"post","link":"https:\/\/successrouter.com\/tech\/c-tool-to-download-the-list-of-image-urls\/","title":{"rendered":"C# Tool to download the list of image URLs"},"content":{"rendered":"\n<p>If you are looking for a tool or exe which you can use to download the images by URLs then you can try below one<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/ranjit-singh-cc\/DownloadImagesByUrl\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/ranjit-singh-cc\/DownloadImagesByUrl<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Code wise it pretty much simple &#8211; You put all the image URLs in url.txt file, and tool iterate over all those URLs and download it in provided destination folder<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">static void Main() {\n\tConsole.WriteLine(\"Enter destination folder path to save images: \");\n\tstring destinationFolder = Console.ReadLine();\n\tstring urlFileName = \"urls.txt\";\n\tif (Directory.Exists(destinationFolder) == false)\n\t\tConsole.WriteLine(\"destination folder not found\");\n\telse if (File.Exists(urlFileName) == false)\n\t\tConsole.WriteLine(\"urls.txt file not found\");\n\telse {\n\t\tstring[] urls = File.ReadAllLines(urlFileName);\n\t\tint count = 0;\n\t\tConsole.Write(\"Images download: 0\");\n\t\tforeach (string url in urls) {\n\t\t\tif (DownloadImage(url, Path.Combine(destinationFolder, Path.GetFileName(url)))) {\n\t\t\t\tcount++;\n\t\t\t\tConsole.Write(\"\\rImages download: {0}\", count);\n\t\t\t}\n\t\t}\n\n\t\tConsole.WriteLine(\"\\n{0} images download\", count);\n\t}\n\n\tConsole.WriteLine(\"Press any key to exit\");\n\tConsole.ReadKey();\n}\n\nprivate static bool DownloadImage(string imgUrl, string fileName) {\n\tbool error = false;\n\ttry {\n\t\tusing (WebClient client = new WebClient()) {\n\t\t\tStream stream = client.OpenRead(imgUrl);\n\t\t\tif (stream != null) {\n\t\t\t\tBitmap bitmap = new Bitmap(stream);\n\t\t\t\tImageFormat imageFormat = ImageFormat.Jpeg;\n\t\t\t\tif (bitmap.RawFormat.Equals(ImageFormat.Png)) {\n\t\t\t\t\timageFormat = ImageFormat.Png;\n\t\t\t\t}\n\t\t\t\telse if (bitmap.RawFormat.Equals(ImageFormat.Bmp)) {\n\t\t\t\t\timageFormat = ImageFormat.Bmp;\n\t\t\t\t}\n\t\t\t\telse if (bitmap.RawFormat.Equals(ImageFormat.Gif)) {\n\t\t\t\t\timageFormat = ImageFormat.Gif;\n\t\t\t\t}\n\t\t\t\telse if (bitmap.RawFormat.Equals(ImageFormat.Tiff)) {\n\t\t\t\t\timageFormat = ImageFormat.Tiff;\n\t\t\t\t}\n\n\t\t\t\tbitmap.Save(fileName, imageFormat);\n\t\t\t\tstream.Flush();\n\t\t\t\tstream.Close();\n\t\t\t\tclient.Dispose();\n\t\t\t}\n\t\t}\n\t}\n\tcatch (WebException ex) {\n\t\terror = true;\n\t\tConsole.WriteLine(ex.Message);\n\t}\n\tcatch (ExternalException ex) {\n\t\terror = true;\n\t\tConsole.WriteLine(\"Something is wrong with Format -- Maybe required Format is not applicable here : {0} \", ex.Message);\n\t}\n\tcatch (ArgumentNullException ex) {\n\t\terror = true;\n\t\tConsole.WriteLine(\"Something Wrong with Stream : {0}\", ex.Message);\n\t}\n\n\treturn !error;\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you are looking for a tool or exe which you can use to download the images by URLs then you can try below one https:\/\/github.com\/ranjit-singh-cc\/DownloadImagesByUrl Code wise it pretty much simple &#8211; You put all the image URLs in url.txt file, and tool iterate over all those URLs and download it in provided destination&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,19],"tags":[20,11],"_links":{"self":[{"href":"https:\/\/successrouter.com\/tech\/wp-json\/wp\/v2\/posts\/75"}],"collection":[{"href":"https:\/\/successrouter.com\/tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/successrouter.com\/tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/successrouter.com\/tech\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/successrouter.com\/tech\/wp-json\/wp\/v2\/comments?post=75"}],"version-history":[{"count":1,"href":"https:\/\/successrouter.com\/tech\/wp-json\/wp\/v2\/posts\/75\/revisions"}],"predecessor-version":[{"id":77,"href":"https:\/\/successrouter.com\/tech\/wp-json\/wp\/v2\/posts\/75\/revisions\/77"}],"wp:attachment":[{"href":"https:\/\/successrouter.com\/tech\/wp-json\/wp\/v2\/media?parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/successrouter.com\/tech\/wp-json\/wp\/v2\/categories?post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/successrouter.com\/tech\/wp-json\/wp\/v2\/tags?post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}