Solved

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

Posted on 2009-05-07
2
1,550 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 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

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

Suggested Solutions

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…
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 …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 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