C# Function to Check if File Is Open
social.msdn.microsoft.com › forums › vstudioJul 18, 2013 · Hi, As the user replied, it requires file stream to check file it is opened or not. If you need a function and if you want to use that function many places, create some static function with filestream and check file is opened or not. Please find the below link for your reference, http://stackoverflow.com/questions/2987559/check-if-a-file-is-open. Balaji -Please click mark as answer if my reply solves your problem.
[Solved] c# checking if a file is already open - CodeProject
www.codeproject.com › questions › 493093Nov 13, 2012 · protected virtual bool IsFileinUse(FileInfo file) { FileStream stream = null; try { stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None); } catch (IOException) { // the file is unavailable because it is: // still being written to // or being processed by another thread // or does not exist (has already been processed) return true; } finally { if (stream != null) stream.Close(); } return false; }