CodeKicks.com
Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Monday, September 25, 2006

Getting a value (string) from a resource file (Culture specific) in .NET

Description: This shows a simple example of retrieving a 'Hello' string from the resource (resx) files in a project.

/// <summary>Gets the 'Hello' string from the resource file given a 
/// specific culture.</summary>
/// <param name="cInfo">
/// The culture to use to get the file.</param>
/// <returns>The string value of the 'Hello' resource.</returns>
public string GetHello( CultureInfo cInfo )
{
//The Namespace should be the default namespace of the project,
//for example, say you're
//default namespace is 'ConsoleApp' you would put 'ConsoleApp'.
//The ResourceName should be the name of the default resource name.
//In your project you should
//have (for example) 'MyResources.resx' (the default) and
//then language specific ones, for example
//'MyResources.fr-FR.resx' would be the French version.

ResourceManager resourceManager = new ResourceManager

( "NAMESPACE.RESOURCENAME",

GetType().Assembly );

return resourceManager.GetString( "Hello", cInfo);

}

Post a Comment