?
Solved

Access the .resx file in runtime.

Posted on 2010-08-16
10
Medium Priority
?
437 Views
Last Modified: 2012-08-13
Hello,

I want to access the .resx file in runtime.

For example: I have a message for each language and I need to access in accordance with the CurrentUICulture and show to the user.

How can I do?

Thanks!
0
Comment
Question by:Rybius
[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
  • 4
  • 4
  • 2
10 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 33445022
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 33445033
Walkthrough: Using Resources for Localization with ASP.NET  
http://msdn.microsoft.com/en-us/library/fw69ke6f(VS.80).aspx

Introduction to the resources .resx and .resources files: Part I (and following)
http://www.c-sharpcorner.com/UploadFile/yougerthen/105032008041615AM/1.aspx
0
 
LVL 16

Expert Comment

by:kris_per
ID: 33445095

Add a resource file named 'Resources.resx'
Add a string resource in resx file  named Hello with value "Hello"
In the code, add the line:
MessageBox.Show(Resources.Hello)
This will show the message "Hello"

To localise it:
Add a resource file named 'Resources.fr.resx' (note the part "fr" in the name; this means this is the resource for French)
Add a string resource named Hello with value "Hello in French"

That's it. If you run the same code in a machine with french settings, the same message box will display "Hello in French".

If the machine is in English settings, French settings can be forced by setting value CurrentUICulture like:
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("fr-FR");
MessageBox.Show(Resources.Hello)

Hope this helps.


0
Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

 

Author Comment

by:Rybius
ID: 33445489
Hi, kris per!

MessageBox.Show (Resources.Hello);
This way is not possible to access a string resource in the Local_Resources.
Hello is not recognized.

Using Resources.Resource1.Hello, I can access the Hello only if in Global Resources.
How can  I do to access a resource string if in Local_Resources?

Can you help me?

Thanks!
0
 
LVL 16

Expert Comment

by:kris_per
ID: 33445529

Try like:

MessageBox.Show (Properties.Resources.Hello);

OR

Add the Properties namespace in usings like:

using WindowsApplication1.Properties.
0
 

Author Comment

by:Rybius
ID: 33445566
Hi, Dhaest!


Following the example and doing like this, I could not access the contents of Hello that is in Local_Resources.
The str returns NULL.

            ResourceManager rm = new ResourceManager("Resources.Resource1",
            Assembly.GetExecutingAssembly());

            String str = rm.GetString("Hello");
           Console.WriteLine(str);

Can anyone help me?

Thanks!
0
 

Author Comment

by:Rybius
ID: 33445599
I am using a WebApplication and there is no "properties"
0
 
LVL 16

Expert Comment

by:kris_per
ID: 33445610

For web app:

For global resources, Resources.Resource1.Hello will work...
 
For local resources, you have to use:

string helloValue = GetLocalResourceObject("Hello")

in the page code..
0
 
LVL 16

Accepted Solution

by:
kris_per earned 2000 total points
ID: 33445636

public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string helloValue = GetLocalResourceObject("Hello").ToString();
        }
    }

Open in new window

0
 

Author Comment

by:Rybius
ID: 33445718
Yes!

Now it worked!

Thanks!
0

Featured Post

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

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 …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

777 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