Sep 2, 2010

Enumerate Embedded Resource Names

How to know and enumerate names of all resources, embedded into assembly?

Well, we know how to load embedded font to memory from resources, but... stream, returned from GetManifestResourceStream is always null??

Ok, you have to be sure about resource name. In general resource name consists from {assembly namespace}.{folder}.{file name}. If your resource not in folder at solution space than it simply {assembly namespace}.{file name}. And at last property of file should be "Embedded Resource".


If you not sure about resource names in your application, you can enumerate available resources.

Assembly executingAssembly = Assembly.GetExecutingAssembly();

foreach ( string resourceName in executingAssembly.GetManifestResourceNames() )
{
  listBox1.Items.Add( resourceName );
}


Download code sample

Read Windows Forms in Action: Second Edition of Windows Forms Programming with C#

No comments:

Post a Comment