Check whether a file is in use or not
/// <summary> /// This function checks whether the file is in use or not. /// </summary> /// <param name="filename">File Name</param> /// <returns>Return True if file in use else false</returns> public static bool IsFileInUse(string filename) { bool locked = false; FileStream fs = null; try { fs = File.Open(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); } catch (IOException ) { locked = true; } finally { if (fs != null) { fs.Close(); } } return locked; }