title: C# extract an embedded resource from assembly to a specific location in pc?
body: <p>How can I with button click export a file (file types: .jpg, .txt, .dll, ... etc) from my application resource code to a specific location on my computer (for example: C: \ drive)
  I tried this code with button click:
  <em>Main Code:</em></p>
  
  <pre><code>Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ApplicationName.Files.name.dll");
          FileStream fileStream = new FileStream("name.dll", FileMode.CreateNew);
          for (int i = 0; i &lt; stream.Length; i++)
              fileStream.WriteByte((byte)stream.ReadByte());
          fileStream.Close();
  </code></pre>
  
  <p>But the application stoped and show me this error:
  <em>Error Message:</em></p>
  
  <pre><code>System.NullReferenceException: 'Object reference not set to an instance of an object.'
  
  stream was null.
  </code></pre>
  
  <p>More Informations:</p>
  
  <p>1) I upload a .dll file to my resources.</p>
  
  <p>2) I changed from this file Build Action to = "Embedded Resource".</p>
  
  <p>I tried with Clint's help below.
  Images of my project now:</p>
  
  <p><a href="https://i.stack.imgur.com/PW8cM.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p><a href="https://i.stack.imgur.com/yfcIr.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p><a href="https://i.stack.imgur.com/5tzGQ.png" rel="nofollow noreferrer">enter image description here</a></p>