tags:

views:

23

answers:

1

I'm making a map creator that chooses images randomly from various sets. What I'm trying to do is set up subfolders in Resources and put the different images in each folder - e.g., a folder for streets, a folder for monuments, etc. Then I just make an array of images out of the files in the folder, and pick one.

For some reason, I can't find a simple way of getting at the subfolders. I've tried using IO.Path.GetFullPath(My.Resources.ResourceManager.BaseName) and appending the folder name to the end of it, but no luck.

Is there some other way of getting the path? Is it even possible to use subfolders of Resources? Is there a better way of doing what I'm trying to accomplish? I'd really like to avoid creating the image arrays by hand.

A: 

It is quite unclear to me how you created subfolders for Resources. Which is probably the source of your problem. My.Resources refers to resources that you add in the Project + Properties, Resources tab. Those resources get embedded into your program, they become part of the assembly itself. You can't get a path for it such a resource, it isn't a file. You have to use My.Resources.ResourceManager to retrieve them, it uses Assembly.GetmanifestResourceStream() internally to get to the embedded data inside the assembly.

Not sure where you want to go with this, but if you actually want to use files in a folder instead of an embedded resource then you should not use My.Resources. Doing this is a bit of a hassle because you have to copy the files from your project directory to the bin\Debug and bin\Release directory. Using My.Resources is usually the preferred solution, especially since the user doesn't get ready access to your art, but it doesn't let you organize the resources into folders. Let us know what you really want to do.

Hans Passant
I created subfolders in the project tree - they show up when I look at it in Solution Explorer and in Explorer.I'd like to be able to have lists of different kinds of images that I don't have to create by hand. So instead of typing My.Resources.street1, My.Resources.street2, etc, I can just drop all the files into a folder called Streets and then later retrieve everything from that folder.
Swordgleam
Hmya, you are talking about files, not resources. They are stored in sub-directories of your project, no way for your program to read them. You can change their Build Action property to "Embedded resource" so they get added to the assembly. But that won't reproduce the folder structure you had. And you'd need Assembly.GetManifestResourceStream to read them. I'm fairly sure this is not what you intended. Use Project + Properties, Resource tab to add resources that you can read with My.Resources
Hans Passant
So there's no way of having any kind of easily accessible folder structure?
Swordgleam
You are in stage 3 of the five stages of grief. If it is really important then you can create separate assemblies that store resources. Still no use for My.Resources. Stage 4 could be "I'll just prefix their name with a string that resembles a folder name". That would work.
Hans Passant
That's what I've been doing so far, but it seems clumsy and inelegant. But at least now I can do it the clumsy and inelegant way without feeling guilty about it. That's something.
Swordgleam
Wise words, impressive how fast you went through the stages. You'll do well.
Hans Passant