[Solved] Does this code block the file? [closed]


Depending on what you want you could add a fourth parameter to the File.Open method.

To open the file with read only access and allow subsequent opening of the file for reading:

private Stream GetFileStream(String path) {
    return !File.Exists(path) ? null : File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
}

This allows read and write:

private Stream GetFileStream(String path) {
    return !File.Exists(path) ? null : File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
}

This blocks this or other processes:

private Stream GetFileStream(String path) {
    return !File.Exists(path) ? null : File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None);
}

File.Open Method

4

solved Does this code block the file? [closed]