Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4065894
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:04:19+00:00 2026-05-20T16:04:19+00:00

I can open a FileStream with new FileStream(logfileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); Without locking the

  • 0

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)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:04:19+00:00Added an answer on May 20, 2026 at 4:04 pm

    No… If you look with Reflector you’ll see that in the end File.ReadLines opens a FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 0x1000, FileOptions.SequentialScan);

    So Read-only share.

    (it technically opens a StreamReader with the FileStream as described above)

    I’ll add that it seems to be child’s play to make a static method to do it:

    public static IEnumerable<string> ReadLines(string path)
    {
        using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 0x1000, FileOptions.SequentialScan))
        using (var sr = new StreamReader(fs, Encoding.UTF8))
        {
            string line;
            while ((line = sr.ReadLine()) != null)
            {
                yield return line;
            }
        }
    }
    

    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 as ReadLines("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)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Microsoft website has the code snippet: using (FileStream fsSource = new FileStream(pathSource, FileMode.Open,
I have the following lines of code: xslt.Load(XmlReader.Create(new FileStream(@C:\website\TransList.xslt, System.IO.FileMode.Open))); xslt.Transform(mydoc.CreateReader(),null, sw); It works
In flash you can open a file on the user's computer. In flash 9
If I can open a connection to an MS Access file in C#, how
how I can calculate MD5 hash for a file that is open or used
I open a FileStream to be written to Asynchronously. m_oFile.BeginRead(arrInputReport, 0, m_nInputReportLength, new AsyncCallback(ReadCompleted),
I have to browse for and open a file in AIR. I can access
I'm creating a class that can read from a dicom file. This is basically
I need to continuously read a log file to detect certain patterns. How can
I am trying to open a Word file for reading using a FileStream in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.