Saturday, July 5, 2008

Registration and Persistance of Custom Culture in .NET Framework

Writing the previous post about Creating a Custom Culture in .NET Framework, one question came in my mind: where the information about this new custom culture is stored on the computer? what the register method does with the CultureAndRegionInfoBuilder instance? And after some research work, I have got the needed details.

Registration of Custom Culture
The registration process, when calling the Register() method, does the following:

1. An .nlp file is created. This file contains all information defined in the CultureAndRegionInfoBuilder instance.

2. Next, the .nlp file is stored in the %WINDIR%\Globalization system directory on the computer (i.e. C:\WINDOWS\Globalization\). Hence, the culture information will still be available when the computer is restarted at a later time.

Note: Since the .nlp file is stored in a system directory, to register a custom culture you must have administrative priviledges on the computer.

3. The final step is the preparation of the .NET Framework to search the %WINDIR%\Globalization system directory the next time there is a request to create a new custom culture. An InvalidOperationException will be thrown if an attempt to register a culture more than once is made.

Persistance of Custom Culture
Another interesting feature about the CultureAndRegionInfoBuilder is its ability to write an XML representation of the object to a specified file. This can be achieved using the Save() method.

// save the new culture
// for instantiation of the infoBuilder object, see previous post

No comments: