Created
January 18, 2019 11:29
-
-
Save sdurandeu/5a7087caec6396aa9c152a430aba361d to your computer and use it in GitHub Desktop.
[C#] Open a file for reading but don't lock it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Stream stream = null; | |
| try | |
| { | |
| stream = File.Open(Path.Combine(this.applicationPath, fileName), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); | |
| using (var reader = new StreamReader(stream)) | |
| { | |
| stream = null; | |
| return reader.ReadToEnd(); | |
| } | |
| } | |
| finally | |
| { | |
| if (stream != null) | |
| { | |
| stream.Dispose(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment