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