Sunday, June 7, 2009

2 Minute at Resource File in .Net

The .resx resource file format consists of XML entries, which specify objects and strings inside XML tags. One advantage of a .resx file is that when opened with a text editor (such as Notepad or Microsoft Word) it can be written to, parsed, and manipulated. When viewing a .resx file, you can actually see the binary form of an embedded object (a picture for example) when this binary information is a part of the resource manifest. Apart from this binary information, a .resx file is completely readable and maintainable.

Note Do not use resource files to store passwords, security-sensitive information, or private data.

I think the main advantage of using .NET resource file(or resx file) is that you can make full use of the built-in API or coding syntax support. For example, .NET provide "ResourceManager Class" to help you programmatically load resource keys from resource file or resx file. Also, net resource file can be embeded into assembly. If you're using custom xml solution.

If you're using .net resource model(resource file or embeded in assembly), then, you should not change them frequently or dynamically at runtime. Because when .net application running, the resource items will be loaded into memory after it is used, just like it load the required assemblies. Therefore, it won't let you to flexibly update and refresh it immediately if you changed them when the application is running.


you can add multiple such resx files in a project. When you build the project, they will be compiled(as embeded resource) into your assembly(or separate satellite
assemlies that contains resource for specific cultures).

For ASP.NET application, it has some further encapsulated functionality.You can provide a local resource file for each aspx page or serveral global resource files for the entire application. These resource items are easy to reference in your aspx page(both through declarative syntax or programatic code)