How to List items in a resource file

T

Turbot

Hello, After much searching, I have finally determined how to add gif
files into a resource and then get them out again in VB.NET. I have
created a resx file and have inserted a bunch of GIF files using a
resource editor that I got from CodeProject. I am then using the
following code to apply one of the graphics to an Image object:

Dim objRM As New
System.Resources.ResourceManager("TutorPro.resHighlights",
Me.GetType.Assembly)
SelectedAsset.Image = CType(objRM.GetObject("Mountain"), Image)

Where 'resHighlights.resx' is the name of the resource file, 'TutorPro'
is my root namespace and 'Mountain' is the name I gave to the gif file
in the resource.

Here is my question, how do I get a list of all the resources in my
file? I can get individual items if I know their names but what if I
don't? What if I want to enable a user to select a gif from the
resource using a drop down combo? I would want to propogate the combo
box with the list of items but if there are 100s of gifs in the
resource, i don't want to have to hard code each 'items.add' line.

Somebody help me please.....!!!!!
 
L

Larry Lard

Turbot said:
Hello, After much searching, I have finally determined how to add gif
files into a resource and then get them out again in VB.NET. I have
created a resx file and have inserted a bunch of GIF files using a
resource editor that I got from CodeProject. I am then using the
following code to apply one of the graphics to an Image object:

Dim objRM As New
System.Resources.ResourceManager("TutorPro.resHighlights",
Me.GetType.Assembly)
SelectedAsset.Image = CType(objRM.GetObject("Mountain"), Image)

Where 'resHighlights.resx' is the name of the resource file, 'TutorPro'
is my root namespace and 'Mountain' is the name I gave to the gif file
in the resource.

Here is my question, how do I get a list of all the resources in my
file? I can get individual items if I know their names but what if I
don't? What if I want to enable a user to select a gif from the
resource using a drop down combo? I would want to propogate the combo
box with the list of items but if there are 100s of gifs in the
resource, i don't want to have to hard code each 'items.add' line.

Somebody help me please.....!!!!!

The help topic ResourceReader class appears to provide sample code to
do what you want? (Got here by looking at ResourceManager members,
seeing GetResourceSet, looking at ResourceSet, clicking through
IResourceReader etc...)
 
T

Turbot

Hi Larry,

Thanks for pointing me in the right direction. I have finally managed
to do what I wanted using the following code:

Dim objRM As New
System.Resources.ResourceManager("TutorPro.resHighlights",
Me.GetType.Assembly)
Dim objResSet As ResourceSet =
objRM.GetResourceSet(System.Globalization.CultureInfo.InvariantCulture,
True, False)
Dim objEn As IDictionaryEnumerator =
objResSet.GetEnumerator()
While objEn.MoveNext
Call Debug.WriteLine("Name = " & CType(objEn.Key,
String))
End While

I can then use the 'GetObject' method of the 'objResSet' ResourceSet
object to get the resource items.

IAN
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top