OK...part of this code MOST LIKELY makes busy the file I want and i need to release resources otherwise the file can't be used by webclient or anything else:
WebClient webClient = new WebClient();
string remote = "sample.jpg";
string px = Request.PhysicalApplicationPath.ToString();
if (File.Exists(px+"1.jpg") != true)
{
string local = px + "1.jpg";
webClient.DownloadFile(remote, local);
}
else
{
string local = px + "2.jpg";
webClient.DownloadFile(remote, local);
}
try
{
byte A, R, G, B;
Color pixelColor;
Color pixelColor1;
string rt = px + "1.jpg";
string rt1 = px + "2.jpg";
System.Drawing.Image a = System.Drawing.Image.FromFile(rt);
Bitmap bitmapImage = new Bitmap(a);
System.Drawing.Image a1 = System.Drawing.Image.FromFile(rt1);
Bitmap bitmapImage1 = new Bitmap(a1);
List<string> list = new List<string>();
for (int y = 0; y < bitmapImage.Height; y++)
{
for (int x = 0; x < bitmapImage.Width; x++)
{
pixelColor = bitmapImage.GetPixel(x, y);
pixelColor1 = bitmapImage1.GetPixel(x, y);
I get this error.
Line 168: webClient.DownloadFile(remote, local);" [IOException: The process cannot access the file
The problem is that webclient is still hanging on to your file.
Try disposing the webclient so it releases its resources.
WebClient webClient = new WebClient();
string remote = "sample.jpg";
string px = Request.PhysicalApplicationPath.ToString();
if (File.Exists(px+"1.jpg") != true)
{
string local = px + "1.jpg";
webClient.DownloadFile(remote, local);
}
else
{
string local = px + "2.jpg";
webClient.DownloadFile(remote, local);
}
webClient.Dispose()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With