Skip to content

Instantly share code, notes, and snippets.

@sdurandeu
Created January 18, 2019 11:29
Show Gist options
  • Select an option

  • Save sdurandeu/5a7087caec6396aa9c152a430aba361d to your computer and use it in GitHub Desktop.

Select an option

Save sdurandeu/5a7087caec6396aa9c152a430aba361d to your computer and use it in GitHub Desktop.
[C#] Open a file for reading but don't lock it
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