title: File.open() got an exception "A required privilege is not held by the client"
body: <p>The following codes are from a textbook:</p>
  
  <pre><code>namespace FileStreamApp
  {
      class Program
      {
          static void Main(string[] args)
          {
              Console.WriteLine("***** Fun with FileStreams *****\n");
              using (FileStream fStream = File.Open(@"C:\myMessage.dat", FileMode.Create))
              {
  
                  string msg = "Hello!";
                  byte[] msgAsByteArray = Encoding.Default.GetBytes(msg);
  
                  fStream.Write(msgAsByteArray, 0, msgAsByteArray.Length);
                  // Reset internal position of stream. 
                  fStream.Position = 0;
  
                  Console.Write("Your message as an array of bytes: ");
                  byte[] bytesFromFile = new byte[msgAsByteArray.Length];
                  for (int i = 0; i &lt; msgAsByteArray.Length; i++)
                  {
                      bytesFromFile[i] = (byte)fStream.ReadByte();
                      Console.Write(bytesFromFile[i]);
                  }
                  // Display decoded messages. 
                  Console.Write("\nDecoded Message: ");
                  Console.WriteLine(Encoding.Default.GetString(bytesFromFile));
              }
              Console.ReadLine();
          }
      }
  }
  </code></pre>
  
  <p>But when I ran it, I got a runtime error. I can't figure it out. The error says:</p>
  
  <pre class="lang-none prettyprint-override"><code> System.IO.IOException was unhandled
   HResult=-2147023582
   Message=A required privilege is not held by the client.
  
   Source=mscorlib
   StackTrace:
     at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
     at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32       
     rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options,    
     SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean 
     useLongPath, Boolean checkHost)
     at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,   
     FileShare share)
     at System.IO.File.Open(String path, FileMode mode)
     at FileStreamApp.Program.Main(String[] args) in   
     C:\MyVSExamples\FileStreamApp\Program.cs:line 15
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
     at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, 
     String[] args)
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, 
     ContextCallback callback, Object state, Boolean preserveSyncCtx)
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, 
     ContextCallback callback, Object state, Boolean preserveSyncCtx)
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, 
     ContextCallback callback, Object state)
     at System.Threading.ThreadHelper.ThreadStart()
  
     InnerException: 
  </code></pre>