Monday, June 1, 2015

Resource File

Resource File in ASP.NET 
A resource file is a XML file that contains the strings that we want to translate into different
languages. A resource file can be updated dynamically so that user themselves can
modify values in resource files once the application is deployed on the server without
re-compiling the entire application again.

The resource file contains key/value pairs. Each pair is a separate resource. The
key names in a resource file are not case sensitive.

Type of Resources

Resource are
of two types:

  • Local Resources
  • Global Resources
Local Resource Local resource is specific to a single Web page and used for
providing versions of a Web page in different languages. Local resources must be
stored in App_LocalResources sub folder. Global Resource Global resource
is used when we want to share the resources between pages. Resources in global resource
files are also strongly typed. Global resource must be stored in App_GlobalResources
sub folder.

Creating Resources

Local Resource
In Solution Explorer, right-click the name of your Web site, click Add -> Add ASP.NET
Folder, and then click App_GlobalResources Folder. There can only be one such folder
in an application, and it must be located at the root of the application.

Global Resource In Solution Explorer, right-click the name of your Web site,
click Add -> Add ASP.NET Folder, and then click App_LocalResources Folder. There
can be many such folders in an application, and they can be located at any level
of the application.


To create resource files for additional languages, the following name pattern must
be followed:
For global resource files:
name.language.resx
name.language-culture.resx
For local resource files:
pageOrControlName.extension.language.resx
pageOrControlName.extension.language-culture.resx

No comments:

Post a Comment