Solved

How do I read key/value pairs from the Resources.resx file?

Posted on 2009-05-07
2
1,473 Views
Last Modified: 2013-11-08
In my .NET 3.5 WinForm solution, I put a bunch key/value pairs in the Resources.resx file, which my Solution Explorer shows it is under /MyProject/Properties with the AssembleInfo.cs file. My Resources.resx "Build Action" is set to "Embedded Resource" (because I want to protect the values from the end user).

How do I retrieve these key/value pairs in C#? I was doing something like this for the Web.config AppSettings, is there something like this for the Resource.resx file? Also do I have to specify the location or can it be arbitrary since it is embedded.
foreach (string item in ConfigurationManager.AppSettings.AllKeys)

{

    //DO SOMETHING HERE

}

Open in new window

0
Comment
Question by:bemara57
2 Comments
 
LVL 6

Accepted Solution

by:
ViceroyFizzlebottom earned 250 total points
ID: 24331571
Here's an example

#
// specify your resource file name
#
        string resourceFile = file;
#
        // get the path of your file
#
        string filePath = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
#
        // create a resource manager for reading from
#
        //the resx file
#
        ResourceManager resourceManager = ResourceManager.CreateFileBasedResourceManager(resourceFile, filePath, null);
#
        // retrieve the value of the specified key
#
        resourceValue = resourceManager.GetString(key);
0
 
LVL 12

Assisted Solution

by:wht1986
wht1986 earned 250 total points
ID: 24332735
It's event easier since you say the string is in the properties of the project. You can use a syntax like
global::YOUR_PROJECT_NAME.Properties.Resources.YOUR_STRING_KEY

just start typing global:: and the intellisense will kick in
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now