我有我的應用程序中刪除圖片的疑難解答,我用foreach刪除文件夾中的文件。刪除我的應用程序文件夾中的照片
我在我的應用程序中使用了無頭的Skype登錄,查詢聯繫人姓名和聯繫人的照片登錄成功後,但我有問題,當我關閉我的應用程序時,我想刪除我應用程序文件夾中的所有聯繫人照片。查看要刪除的代碼:
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);
}
}
錯誤消息:
The process cannot access the file 'C:\Users\...\mypicture.jpg'
because it is being used by another process.
請幫助我!
確保您要刪除 –
注意你殺了應用程序的所有進程,因爲它仍然在使用該圖片對於正常安裝的應用程序,您不具有對其文件夾的寫入權限。 – Joey