3
votes

Using Visual Studio 2010

How can I enumerate all resources within in a specific resource file (.resx) that lies inside my assembly?

In my project I have a Resources.resx file with 3 text files (string resource). I need to enumerate these 3 files and then use their names to get their contents.

Thanks.

2

2 Answers

6
votes

Use ResXResourceReader from System.Windows.Forms.

It Enumerates XML resource (.resx) files and streams, and reads the sequential resource name and value pairs

public static void Main()
{

  // Create a ResXResourceReader for the file items.resx.
  ResXResourceReader rsxr = new ResXResourceReader("items.resx");

  // Iterate through the resources and display the contents to the console.
  foreach (DictionaryEntry d in rsxr)
  {
      Console.WriteLine(d.Key.ToString() + ":\t" + d.Value.ToString());
  }

 //Close the reader.
 rsxr.Close();

}

5
votes

Found out:

Dim man As New ResourceManager("Discovery.Resources", Assembly.GetExecutingAssembly)
Dim resset As ResourceSet
resset = man.GetResourceSet(CultureInfo.CurrentCulture, True, True)
For Each item As DictionaryEntry In resset
    Console.WriteLine(item.Key)
Next