Thursday, December 27, 2007

Read Resource Value Programmatically By C#

There are two types of resource file in .net framework 2.0. They are

1. Global Resource File and
2. Local Resource File

Global resource file can be read by GetGlobalResourceObject method. This method takes two parameter: resource class and the resource key. The class name associates with the .resx file name that contains global resources. Suppose we want the value of "LoginText" from global resource file, named Resource.resx, then our statement will be like below

GetGlobalResourceObject("Resource", "LoginText");

Local resource file which normally stored in App_LocalResources folder, can be read by GetLocalResourceObject method. GetLocalResourceObject takes a resource name as parameter. so we can get a local resource value by the following way

lblMessage.Text = GetLocalResourceObject("msgInvalidLink").ToString();

Enjoy!

5 comments:

witnes said...

Thanks for sharing this information. It was very helpfull for me.

Tamilvanan said...

Hello,

It is very helpful.
thank u so much.
Have a colorful life with endless happiness.

Tamilvanan.k
Software Developers India. Pvt. Ltd.
tamilv@sdi.la

lavanya said...

Thanks alot..it helpoed me

Unknown said...

thanks alot

Unknown said...

Thanks alot