从网址下载图像

时间:2011-06-02 06:23:55

标签: c# asp.net

我要使用特定网址下载图片,for循环以防一些产品拥有超过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格式....

1 个答案:

答案 0 :(得分:0)

我认为随机给你相同的数字。请参阅此主题以获取修复Random number generator only generating one random number

如果您调试,那么没有调试就会“慢”。另一种选择是使用guids作为文件名

相关问题