Embedding file as resource in dll

* In Visual Studio file properties set Build Action as Embedded Resource

And then you can read a file using this code

private static string ReadResourceFile(string defaultNamespace, string fileName)
{
  var resource = string.Format("{0}.{1}", defaultNamespace, fileName);
  using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource))
  {
    using (var sr = new StreamReader(stream))
    {
      return sr.ReadToEnd();
    }
  }
}

Comments

Popular posts from this blog

Parse XML to dynamic object in C#

C# Updating GUI from different thread