RHaguiuda
RHaguiuda

Reputation: 3259

How enumerate resources inside a resx file programmatically?

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.

Upvotes: 3

Views: 2880

Answers (2)

RHaguiuda
RHaguiuda

Reputation: 3259

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

Upvotes: 5

nan
nan

Reputation: 20296

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();

}

Upvotes: 6

Related Questions