开发者

How can I extract images from urls which are in a csv file?

开发者 https://www.devze.com 2022-12-21 12:41 出处:网络
i have a csv file which开发者_运维问答 has S.no and Url of the 1500 images : i need to save all the images at a time how can i do it in .net with C# ?You can use FileHelpers to extract the URLs from y

i have a csv file which开发者_运维问答 has S.no and Url of the 1500 images : i need to save all the images at a time how can i do it in .net with C# ?


You can use FileHelpers to extract the URLs from your CSV file.

You can then use WebRequest to pick up each file in turn and save it locally.


I'm not sure if you want some code to do this (not really possible given the level of detail supplied) or an idea of how to go about it.

You could connect to the CSV as a DataSource, then programatically step through each DataRow, capturing the image specified by each url with a WebRequest until you reach the end of your DataSet.

You could also make it multithreaded so that multiple image downloads are possible at once.


Read the URLs (using a TextReader) into a datastructure (IList or whatever). Loop over the list and do something like the following for each URL:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)renderingRequest.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader responseStreamReader = new StreamReader(responseStream);

Then write the contents of responseStreamReader to a file using a FileStream created from a FileInfo fi by calling fi.OpenWrite()

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号