I've been learning about resources in C# and the visual C# IDE. I'm confused now. I have read some pages on StackOverflow, like this one how-to-get-the-path-of-an-embebbed-resource and the documentation of Microsoft, but it confused me.
My first question: what are resources: is it the .resources file or is it the files that are inside it, like icons.
second: When I use the GetManifestResourceNames method: do I get the .resources files names or the the names of the files inside it. When I use it in my program, I only get the .resources files, but reading topics like this loop-through-all-the-resources-in-a-resx-file , I get the impression I should get the names of the files inside the .resources file.
Is it me, or is this terminology really a bit confusing? Can anyone make it a little clearer? Thanks for all help.
GetString Method (System. Resources)
'EmbeddedResource' files are placed directly into the executable as manifest resources. All 'Resource' files are put in a special structured manifest resource named ' ProjectName. g. Resources '. Embedded Resources.
Embedded files are called as Embedded Resources and these files can be accessed at runtime using the Assembly class of the System.Reflection namespace. This article will illustrate, how to read and display an embedded Text file and Image file in Windows Application (Windows Forms) in C# and VB.Net. Download Code Sample.
Resources are any file you compile by flagging it as an "EmbeddedResource" this simply merge the file into the assembly. GetManifestResourceNames()
is just an enumerator that give us the name of all embedded compiled resources files, e.g. MyAssembly.resources
. The actual resource elements need to be enumerated via a ResourceSet
which loads this resources file.
I dont know if you still need the answer to this question but from my experience GetManifestResourceNames()
returns the names of the .resource
files embedded in your assembly.
If you want to access the individual resources you could so something along the lines of:
Assembly assembly = Assembly.LoadFrom(assemblyName);
string[] names = assembly.GetManifestResourceNames();
ResourceSet set = new ResourceSet(assembly.GetManifestResourceStream(names[0]));
foreach (DictionaryEntry resource in set)
{
Console.WriteLine("\n[{0}] \t{1}", resource.Key, resource.Value);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With