Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Access the .resx file in runtime.

Posted on 2010-08-16
10
Medium Priority
?
444 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
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!

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

609 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