简体   繁体   English

从 url 下载图像

[英]Download of image from url

I've to download the images from particular URL using, for loop in case some products having more than 5 images.. when i click the product button some of the images only getting download not all images..but when i debug the corresponding code works fine, ie, its downloads all the images..properly.我必须使用 for 循环从特定的 URL 下载图像,以防某些产品的图像超过 5 个。当我单击产品按钮时,一些图像仅下载而不是所有图像。但是当我调试相应的代码时工作正常,即它下载所有图像..正确。 is this due to some cache.... or image file is in Gif format....这是由于一些缓存......还是图像文件是 Gif 格式......

This is My Code这是我的代码

for (int i = 0; i < obj.Count; i++)
{
PartNAme = (obj[i].ToString().Split('='))[1];
_prtnm = PartNAme.ToString().Split(';')[0];

//this is url , source for the image
_final_URI = _URI + _Prod_name + '/' + _prtnm + ".GIF";


WebClient client = new WebClient();

string strtempname = DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "");

rnd = new Random(100);

string _strfile = "PNImage" + strtempname + rnd.Next().ToString() + ".gif";

string _path = "../Images/PNImage/" + _strfile;

string _PPath = Server.MapPath(_path);

//to download image from source url, and path to save the image file
client.DownloadFile(_final_URI, _PPath);
}

in above code when i debug the image files are getting downloaded properly, but while running without debug some image files gets repeated so instead of getting original image file, old/same image file gets downloaded instead... is this due to some cache.... or image file is in Gif format....在上面的代码中,当我调试图像文件时,图像文件被正确下载,但是在没有调试的情况下运行时,一些图像文件被重复,所以不是获取原始图像文件,而是下载旧/相同的图像文件......这是由于一些缓存。 ...或图像文件为 Gif 格式....

I think that random gives you the same number.我认为随机给你相同的数字。 See this thread for a fix Random number generator only generating one random number请参阅此线程以获取仅生成一个随机数的修复随机数生成器

If you debug you are way "slower" that without debugging.如果您进行调试,则无需调试就会“变慢”。 Another option would be to use guids as filename另一种选择是使用guids作为文件名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM