Reader Level:

Retrieve All Items From Resource Files

Posted by Ibrahim Ersoy Articles | Windows Store Apps October 23, 2012
While developing for the Windows 8 Platform, you'd like to use items in a resource file for a Windows store application. Here I'll show you how to get all the strings in a Resource file.
  • 0
  • 0
  • 4382

If you're planning to use Resource Files to write items and then read them, you're on the wrong track.

Because Windows Store Applications don't support ResourceWriter classes, but that doesn't mean you can't use Resource Files!

Before beginning working with Resource Files, make sure you've created a Windows Store Application (C# and XAML) and added a Resource File to your project.

Name it "Resource.resw" or anything not related to a folder name in your project.

Add two items such as:

Name    |          Value
Note1         First Note
Note2         Second Note

Then in your application add these namespaces:

using Windows.ApplicationModel.Resources.Core;
using Windows.ApplicationModel.Resources;

Now create 2 variables:

List<string> reslist = new List<string>();
ResourceMap rmap = ResourceManager.Current.MainResourceMap;

Using the ResourceManager's MainResourceMap we're retrieving all the maps provided and storing these maps in a ResourceMap variable.

Now add this code to retrieve all the string items from the Resources file.We used substring while querying because the original query gives folder names too, so we had to crop the useful part from it. Resources is 9 digits + 1 (for removing backslash character too).

foreach (string str in rmap.Keys) 
if ((str.StartsWith("Resources"))) 


foreach (string str in reslist) 
ResourceLoader rl = new ResourceLoader("Resources");listBox1.Items.Add(rl.GetString(str));

Finally we're listing all the strings in a listbox:


Hope it helps you to.