SharePoint Dev Kata 2 – Working With Resource Files
Posted in News on 01/19/2010 04:47 pm by hilton.giesenowOne of the practices I’m trying to improve on in my teams is working with string literals. In Feature XML files, for instance, we can set the DisplayName of a Site Column to pull from a localized resource file instead of being hard-coded. See here for an introduction by Ton Stegeman. In addition to being able to localize the values, the resource file creates a strongly-typed “code behind”, if you like, which is a wrapper resource manager to allow you to access the values from code directly. This Kata is about practicing the pieces of this.
Here are the steps:
- Create a new Feature called “Testing Resources Feature”
- Add a Site Column called “My Test Column”
- Add a Resource file
- Create entries in the Resource File for these two strings
- Use the strings in the Feature and Site Columns xml files
- Modify the Site Column’s “Name” property to also use a Resource setting
- Create a new list definition in the Feature to use the new Site Column
- Add an item to the list in the Feature Receiver and use the strongly-typed Resource key to access the field