Thought I´d share a little light on my experiences around working with resource file (.resx) in SharePoint 2010.
First of all, we have three “types” of resource file in SharePoint. I´m not going to go into detail about that but you can read more about it here if you are interested (it´s the same lineup in 2010 as 2007).
My “mission” is as always to make SharePoint “behave” like an asp.net application (where we have got the trusted App_GlobalResources folder). In SharePoint there is also SharePoint resources (SharePointRoot\Resources) which we can use in features and such. I would like to use the same .resx file for both of these types of resources and not maintain two of them.
In SharePoint 2007 (with Visual Studio 2008) I usually had the resources in a folder at the root of my project, called Resources, and then I XCopied (or RoboCopied) the resource files to 12/Resources and 12/CONFIG/Resources. Why these two locations?
Well, in 2007 we needed to run stsadm –o copyappbincontent to copy stuff from 12/CONFIG/Resources to the IIS virtual directory/App_GlobalResources because that was the only way to get the files over there in safe manner.
In 2010 we have some new options. Let me walk you through those:
The mapped folder approach
Add a new mapped folder which maps to the resources folder in the SharePoint root.
This adds a new folder to the root of your project called” Resources” (resembles the way I did it in 2007) and all the files you put there will end up in SharePointRoot/Resources (or 14/Resources). Great!
What about making those files also appear in App_GlobalResources. No problem, open up the packaging explorer and go into edit mode of the manifest.xml file:
Click that link and we now have the ability to add App_Global Resource files like this:
A little note here though: If you want to add files from that mapped folder (called Resources) you will have to specify them like above (Resources\[your resx file])
Also, you can´t rename that mapped folder into something more relevant (like MyResources). Visual Studio will keep the path as Resources (no mather what name you´ll give it) in the WSP as you can see below:
When the deployment takes place the files are also copied to App_Global resources like you can see below:
But wait…they are copied into a folder named Resources! And as I stated above, you can´t change that name…damn it!
The App_GlobalResoures SPI approach
Another way to do it, even though I don´t like maintaining two separate files, is to add a new Empty Element SPI (Project Item):
I name mine App_GlobalResources because that will give me a folder with that name inside my project and that will look like it would in an asp.net project…I like that!
Change the deployment type to AppGlobalResource and also change the deployment location like:
Remove that Path stuff (the arrow is showing that in the before and after picture above). Why?
Otherwise you will get a folder named [Project Name]\App_GlobalResources inside your App_GlobalResource folder…not OK!
I like this approach better than the first one because it gets rid of that Resources folder name inside App_GlobalResources (even though it works with more than one WSP writing into that folder…looks weird but works).
You can of course keep that other mapped folder for your SharePoint specific resources (don´t forget to remove the stuff from the manifest though) and it will look like this:
The conclusion will be that it now works much better….not perfect but a hell lot more flexible now that in 2007!