[.NET] Access Embedded Resource File

Sometimes it’s necessary to embed a resource file in the assembly in order to make the distribution easier, or to protect the resource file.

In order to set the resource as embedded, it’s necessary to change the “Build Action” to Embedded Resource:

Then, on the code, it’s just a matter of getting the resource stream from the assembly.

Note: It’s necessary to use the namespace before the filename: “Namespace.Filename.extension”

Assembly assem = this.GetType().Assembly;
Stream stream = assem.GetManifestResourceStream("Namespace.Filename.extension");

Leave a Reply

Your email address will not be published. Required fields are marked *



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>