I have troubleshoot with delete picture in my application, I used foreach to delete file in folder.
I used Headless skype login in my applicaton with query contact name and contact's photos After login succeed, but I have problem when I closed my app ,I wanna delete all contact's photos in my app's folder .See the code to delete:
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
var applicationDirectory = System.IO.Path.GetDirectoryName(assemblyLocation);
var imagesDirectory = System.IO.Path.Combine(applicationDirectory, "img");
var contact_photo = Directory.EnumerateFiles(imagesDirectory,
"*.jpg",SearchOption.TopDirectoryOnly);
if (contact_photo != null)
{
foreach (var photo in contact_photo)
{
Console.WriteLine(photo);
File.Delete(photo);
}
}
Error Message:
The process cannot access the file 'C:\Users\...\mypicture.jpg'
because it is being used by another process.
Help me please!