A protected virtual bool IsFileLocked(FileInfo file) {
FileStream stream = null;
try {
stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
} catch (IOException) {
return true;
} finally {
if (stream != null)
stream.Close();
}
return false;
}
B try { using (Stream stream = new FileStream("MyFilename.txt", FileMode.Open)) { } } catch { }
C internal static bool FileOrDirectoryExists(string name) { return (Directory.Exists(name) || File.Exists(name)) }
D FileInfo file = new FileInfo("file.txt"); if (file.Exists) { // TO DO }