title: FileStream position is off after calling ReadLine() from C#
body: <p>I'm trying to read a (small-ish) file in chunks of a few lines at a time, and I need to return to the beginning of particular chunks. </p>
  
  <p>The problem is, after the very first call to </p>
  
  <pre><code>streamReader.ReadLine();
  </code></pre>
  
  <p>the <code>streamReader.BaseStream.Position</code> property is set to the end of the file! Now I assume some caching is done in the backstage, but I was expecting this property to reflect the number of bytes that <strong>I</strong> used from that file. And yes, the file has more than one line :-) </p>
  
  <p>For instance, calling <code>ReadLine()</code> again will (naturally) return the next line in the file, which does not start at the position previously reported by <code>streamReader.BaseStream.Position</code>.</p>
  
  <p>How can I find the <em>actual</em> position where the 1st line ends, so I can return there later? </p>
  
  <p>I can only think of manually doing the bookkeeping, by adding the lengths of the strings returned by ReadLine(), but even here there are a couple of caveats:</p>
  
  <ul>
  <li>ReadLine() strips the new-line character(s) which may have a variable length (is is '\n'? Is it "\r\n"? Etc.)</li>
  <li>I'm not sure if this would work OK with variable-length characters</li>
  </ul>
  
  <p>...so right now it seems like my only option is to rethink how I parse the file, so I don't have to rewind.</p>
  
  <p>If it helps, I open my file like this:</p>
  
  <pre><code>using (var reader = new StreamReader(
          new FileStream(
                         m_path, 
                         FileMode.Open, 
                         FileAccess.Read, 
                         FileShare.ReadWrite)))
  {...}
  </code></pre>
  
  <p>Any suggestions?</p>