Embedded Resources
Resource files can be made available to an assembly by marking their Build Action property to “Embedded Resource”.
If “license.rtf” is in a subfolder “Resources” of an assembly whose default namespace is “
the following code will recover the resource as a string:
System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
string rsrcName = “
System.IO.Stream s = a.GetManifestResourceStream(rsrcName);
System.IO.StreamReader sr = new System.IO.StreamReader(s);
string license = sr.ReadToEnd();
The example code in the documentation builds the resource name from the assembly’s name:
string rsrcName = a.GetName().Name + ".Resources.license.rtf";
This doesn’t seem to work in general, since the assembly name can differ from the default namespace.
Use ILDASM to view the assembly manifest when in doubt about what a resource is being named.