I created a simple method that deletes an image from the server.
public static void deleteImage(string deletePath)
{
if (!File.Exists(deletePath))
{
FileNotFoundException ex = new FileNotFoundException();
throw ex;
}
try
{
File.Delete(deletePath);
}
catch (IOException ex)
{
throw ex;
}
catch (Exception ex)
{
throw ex;
}
}
The method works great on the Visual Studio development server, but when I try it out on the live server that uses IIS I keep getting an error saying the resource is in use. It eventually works after about 10 attempts but I can’t afford this.
Maybe I need to “lock” the file for this to work on IIS?
Thanks!
try this