从URL图像下载 [英] Download of image from url

查看:110
本文介绍了从URL图像下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经下载使用从特定网址的图像,循环的情况下,有超过5图像部分产品..当我点击按钮的产品某些图像只获得下载并非所有images..but当我调试相应的code正常工作,也就是说,它的下载所有images..properly。
这是由于一些缓存....或图像文件是GIF格式....

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, i.e, its downloads all the images..properly . is this due to some cache .... or image file is in Gif format....

这是我的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);
}


在上面code,当我调试的图像文件越来越正常下载,但没有调试某些图像文件运行时被重复这样反而得到原始图像文件的,旧的/同一个图像文件被下载,而不是...
这是由于一些缓存....或图像文件是GIF格式....


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....

推荐答案

我认为,随机给你相同的号码。看到这个线程修复<一个href=\"http://stackoverflow.com/questions/767999/random-number-generator-not-working-the-way-i-had-planned-c\">Random数生成器不工作我已经计划的方式(C#)

I think that random gives you the same number. See this thread for a fix Random number generator not working the way I had planned (C#)

如果您调试你的方式慢,没有调试。另一种选择是使用的GUID 作为文件名

If you debug you are way "slower" that without debugging. Another option would be to use guids as filename

这篇关于从URL图像下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆