Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a list of all resources from an assembly

Tags:

c#

wpf

I have a folder with Resources and want to get a list with all paths.

enter image description here

If I set them to an embedded resource, I can get them via

var resources = Assembly.GetExecutingAssembly().GetManifestResourceNames();

When follwing this answer https://stackoverflow.com/a/1935035/6229375, I shouldn't use embedded resource anymore or I'm doing something wrong?

like image 894
Dominic Jonas Avatar asked Mar 05 '23 12:03

Dominic Jonas


1 Answers

From the following blog post:

Files marked with build action of “Resource” are added to a special resx file called ProjectName.g.resx. This file is generated during the build, it is not part of the project. You can access content of the ‘Resource’ files by creating an instance of ResourceManager and calling GetStream(filename). Additionally, in WPF applications you can access these resources via Application.GetResourceStream() in C# and via things like in XAML.

   var resourceManager = new ResourceManager("ConsoleApp5.g", Assembly.GetExecutingAssembly());
    var resources = resourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true,
true);
    foreach (var res in resources)
    {
        System.Console.WriteLine(((DictionaryEntry)res).Key);
    }

where ((DictionaryEntry)res).Value will be Stream.

like image 193
Access Denied Avatar answered Mar 17 '23 16:03

Access Denied