title: Extract embedded resources in C#
body: <p>I have four resource files embedded in my C# executable, 1 python script and 3 perl scripts. I could extract all three perl scripts successfully. But I am not able to extract the python script. I tried so many ways. Could someone please have a look ? Thank you.</p>
  
  <pre><code>public static string ExtractResource(string resourceName)
  {
      string destFile = "";
  
      //look for the resource name
      foreach (string currentResource in System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames() )
          if (currentResource.LastIndexOf(resourceName) != -1)
          {
              string subPath = Common_Utilities.GetTempPath() + "SCRIPTS"; 
              bool isExists = System.IO.Directory.Exists(subPath);
  
              if (!isExists)
                 System.IO.Directory.CreateDirectory(subPath);
  
              string strFile = subPath + "\\" + resourceName;
              string path = System.IO.Path.GetDirectoryName(strFile);
              string rootName = System.IO.Path.GetFileNameWithoutExtension(strFile);
              destFile = path + @"\" + rootName + System.IO.Path.GetExtension(currentResource);
  
              System.IO.Stream fs = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream( currentResource ) ;
  
              byte[] buff = new byte[fs.Length];
              fs.Read(buff, 0, (int)fs.Length);
              fs.Close();
  
              System.IO.FileStream destStream = new System.IO.FileStream(destFile, FileMode.Create);
              destStream.Write(buff, 0, buff.Length);
              destStream.Close();
      }
  
      return destFile;
      // throw new Exception("Resource not found : " + resourceName);
  }
  </code></pre>