[英]Download of image from url
我必须使用 for 循环从特定的 URL 下载图像,以防某些产品的图像超过 5 个。当我单击产品按钮时,一些图像仅下载而不是所有图像。但是当我调试相应的代码时工作正常,即它下载所有图像..正确。 这是由于一些缓存......还是图像文件是 Gif 格式......
这是我的代码
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);
}
在上面的代码中,当我调试图像文件时,图像文件被正确下载,但是在没有调试的情况下运行时,一些图像文件被重复,所以不是获取原始图像文件,而是下载旧/相同的图像文件......这是由于一些缓存。 ...或图像文件为 Gif 格式....
我认为随机给你相同的数字。 请参阅此线程以获取仅生成一个随机数的修复随机数生成器
如果您进行调试,则无需调试就会“变慢”。 另一种选择是使用guids
作为文件名
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.