I can open a FileStream with
new FileStream(logfileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
Without locking the file.
I can do the same with File.ReadLines(string path)?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No… If you look with Reflector you’ll see that in the end
File.ReadLinesopens aFileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 0x1000, FileOptions.SequentialScan);So Read-only share.
(it technically opens a
StreamReaderwith theFileStreamas described above)I’ll add that it seems to be child’s play to make a static method to do it:
This returns an
IEnumerable<string>(something better if the file has many thousand of lines and you only need to parse them one at a time). If you need an array, call it asReadLines("myfile").ToArray()using LINQ.Please be aware that, logically, if the file changes “behind its back (of the method)”, how will everything work is quite undefined (it IS probably technically defined, but the definition is probably quite long and complex)