title: Does FileStream.SafeFileHandle *really* set the current stream position to 0?
body: <p>According to the <a href="http://msdn.microsoft.com/en-GB/library/system.io.filestream.safefilehandle%28v=vs.110%29.aspx" rel="nofollow">MSDN documentation for <code>FileStream.SafeFileHandle</code></a>:</p>
  
  <blockquote>
    <blockquote>
      <p>The SafeFileHandle property automatically flushes the stream and sets the current stream position to 0. This allows the file to be moved or the stream position to be reset by another stream using the SafeFileHandle returned by this property.</p>
    </blockquote>
  </blockquote>
  
  <p>However, my tests seem to indicate that the stream position is <em>not</em> changed.</p>
  
  <p>Consider the following code:</p>
  
  <pre><code>using System;
  using System.IO;
  
  namespace Demo
  {
      internal static class Program
      {
          public static void Main()
          {
              Directory.CreateDirectory("C:\\TEST");
              var buffer = new byte[1024];
  
              using (var file = new FileStream("C:\\TEST\\TEST.BIN", FileMode.Create))
              {
                  file.Write(buffer, 0, buffer.Length);
                  Console.WriteLine(file.Position);  // Prints 1024
                  var dummy = file.SafeFileHandle;
                  // dummy.Dispose();                // Uncommenting this line will make the next line throw.
                  Console.WriteLine(file.Position);  // Still prints 1024!
              }
          }
      }
  }
  </code></pre>
  
  <p>If accessing <code>SafeFileHandle</code> really did reset the current stream position to 0, I'd have expected the second WriteLine() to print 0.</p>
  
  <p>I have other tests where I actually use <code>SafeFileHandle</code> with the Windows API ReadFile() and WriteFile() methods, and even then it doesn't appear to change the file pointer.</p>
  
  <p>I have some code that uses <code>SafeFileHandle</code>, so it's pretty important to me whether the stream position will be changed or not!</p>
  
  <p>Have I misunderstood the documentation, or is it incorrect? Or does it change the stream position <em>sometimes</em>? (That would be a nightmare!)</p>