Determine if a file is locked.

public static bool IsFileLocked(string FullPathAndFileName)
{

 bool IsLocked = false;
 System.IO.FileStream LockTextFileStream = null;
 try {
  LockTextFileStream = new System.IO.FileStream(FullPathAndFileName, IO.FileMode.Open, IO.FileAccess.ReadWrite, IO.FileShare.None);
 } catch {
  IsLocked = true;
 } finally {
  if (LockTextFileStream != null) {
   LockTextFileStream.Close();
  }
 }
 return IsLocked;
}

No comments:

Post a Comment