public static void DeleteUsedXMl() { try { string PhyPath = ConfigurationManager.AppSettings["PhyPath"];//This is my physically address path string filesToDelete = "*.xml"; string[] fileList = System.IO.Directory.GetFiles(PhyPath + "Feeds\\", filesToDelete); foreach (string FileFullName in fileList) { if (!CheckIfFileIsBeingUsed(FileFullName)) { System.IO.File.Delete(FileFullName); } } catch (Exception) { throw; } }
private static bool CheckIfFileIsBeingUsed(string FileFullName) { try { FileStream fs = File.Open(FileFullName, FileMode.Open, FileAccess.Read, FileShare.None); fs.Close(); } catch (Exception exp) { return true; } return false; }
... foreach (string FileFullName in fileList) { try { System.IO.File.Delete(FileFullName); } catch {} }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)