Donnerstag, 11. April 2013

Resource file usage in SharePoint 2010 with Visual Studio 2010

There are two ways to use resource files in SharePoint.
One is with code-behind and the other is to render it in the control.
In the following image you see version (1) in line 9 and version (2) in line 10


Version 1 requires a resx file in the SharePoint 14 hive 'Resources' folder.
Version 2 requires a deployment to App_GlobalResources folder.

Important, if you want to have your resx file to deployed to the 14 hive, first map your project with the SharePoint Resources folder. Then place your resx file in there and you will need to set the Build Action in the resx property to 'Content' otherwise a deployment to the hive won't take place (file will not be physically copied to the hive folder).




Next thing is to click on your feature and set there the property 'DefaultResourceFile' to the neutral resource file and set 'Require Resources' to true.


How to deploy to the App_GlobalResources:
Create in your SharePoint 2010 project a new item "Empty Element". I called it 'ResourceFiles'.
Then you place your resource file in there. To test properly I named it the same and also added the same key with a different value.


When checking the properties of the resx file, set the Deployment Type to 'AppGlobalResource'


Deploy your solution and then check the result.
In my case according to that code


I had this result