The topic is the question, is there a way to access embedded resources folder by name dynamically via string? The closest I think I've gotten is the following code which has error "Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<string>' to 'string'", if i try to get the only folder it should return with [0] it gives error "Cannot apply indexing with [] to an expression of type 'System.Collections.Generic.IEnumerable<string>'"

string prefix = "namespace.folder."

var resourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames().Where(name => name.StartsWith(prefix));

Any help would be much appreciated,
Smalls

Recommended Answers

All 3 Replies

Just running
var resourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
and watching with the debugger gave me this:

    resourceNames   {string[2]} string[]
    [0] "WindowsFormsApplication3.Properties.Resources.resources"   string
    [1] "WindowsFormsApplication3.Form1.resources"  string

Hope it helps a bit.

commented: Thank you for bringing up the array aspect, lacking quite a bit of sleep atm! Cheers +3

Sorta what i came to as well. But by using Assembly.GetExecutingAssembly().GetManifestResourceNames().Where(name => name.StartsWith(prefix)) you can specify a set of the resources that contain the prefix. Afterward I could run resourceNames through a for or foreach to find what im looking for with resourceNames.ElementAt(i)

Glad to have put you on the way. :)
Thanks for the LINQ tips btw.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.