Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-05-07
2
Medium Priority
?
1,667 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 1000 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 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

916 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