Click here to Skip to main content
13,352,175 members (76,154 online)
Click here to Skip to main content
Add your own
alternative version


23 bookmarked
Posted 5 Mar 2009

Custom Resource Provider

, 5 Mar 2009
Rate this:
Please Sign up or sign in to vote.
Custom resource provider to facilitate fetching global resources using HTML markups
Click to enlarge image


.NET provides a very easy way to set resources for your labels in HTML markup itself (as show above) using classes like ResourceProviderFactory and IResourceProvider. This article illustrates a simple example to implement this using ASP.NET & C# (solution attached is created in Visual Studio 2008).


Remember how in .NET 1.1 Resgen tool was used to generate ".resources" file from simple text file and loading the culture specific .resources file in the ResourceManger instance? Well now we have this cool way of reading culture specific resources from resource files for our multilingual applications. This is enabled using class ResourceProviderFactory and IResourceProvider interface. 

Using the Code


In the solution, we have Web client that consumes the CustomResoureProvider library. And we have a library project "CommonResources" that holds all the culture specific resource files. 

In the Default.aspx page, we have a dropdown to select different languages. On selecting different languages, the culture specific resource file to selected language is loaded by the CustomResourceProvider and corresponding resources are rendered.

Web client is informed of the CustomeResourceProvider by specifying globalization tag in the web.config as:

<globalization uiCulture="auto"
culture="auto" resourceProviderFactoryType=
" CustomeResourceProviders.
Version= , Culture=neutral"/>

Another important thing to note here is the overridden method InitializeCulture().

You can always add more resource files for supporting more languages in your multilingual applications. The advantage of this way of reading resources is, to add a new language support to a web application we don't have to make any code changes. All we have to do is add a Resource file with proper culture specific name and have all the resources translated to the new language in this file and you are ready to go. 

Points of Interest

One thing that bugged me while doing this is that when the resource files in the "CommonResources" project (in attached solution) were having the name "Resources.resx", the English resources were getting read fine. But on changing the language, culture specific resources were not getting read but English resources were getting read. I'm guessing that might have something to do with "Resources" being a keyword. Any one having more information in this regard, please do post comments.


  • 5th March, 2009: Initial post


This article, along with any associated source code and files, is licensed under A Public Domain dedication


About the Author

Software Developer (Senior) Geometric
India India
B.E. in Information Technology
MCTS(.NET 2.0 )

You may also be interested in...


Comments and Discussions

GeneralNice work! Pin
Matrix6-Mar-09 21:06
memberMatrix6-Mar-09 21:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 5 Mar 2009
Article Copyright 2009 by sunit_82
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid