Question: Which of the following code samples will check if a file is in use?
A
B
C
D
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 }
Note: Not available