I want to delete my image from folder. But it throws “it is being used by another process.”
Here is my code:
fuProductImage.SaveAs(fileFolderPathTemp + fuProductImage.FileName);
Bitmap orgImage = new Bitmap(fileFolderPathTemp + fuProductImage.FileName);
ResizeAndSaveImages(orgImage, fileFolderPathLarge, fuProductImage.FileName, 66, 66);
File.Delete(fileFolderPathTemp + fuProductImage.FileName);
What should I do to delete this file?
As of request, my suggestion is to put line two and three into a
usingblock like:The reason why this should help is that the
usingensures that theorgImageis correctly being disposed, thus freeing memory and releasing file handles before you call theFile.Delete()function.