Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-05-07
2
Medium Priority
?
1,632 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Stack Overflow Podcast - Developer Story

Welcome to the Stack Overflow podcast recorded Thursday July 20 at Stack Overflow Headquearters in NYC. Your hosts today are podcast regulars Jay Hanlon, David Fullerton, and Ilana Yitzhaki, plus the quite irregular Matt Sherman (Stack Overflow Engineering Manager extraordinaire)

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 shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

688 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