Solved

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

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

821 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