SharePoint 2010 Solutions – Resources

I wrote this guide about how to use resource files in SharePoint 2010 solutions for my company and often reread it, so I thought to translate it to English and share it with you.

Differences with normal resource files
SharePoint doesn’t always refert back to the .resx file if a language specific resource file can’t be found, therefor make sure to fill out all the supported languages entirely!

Different locations and uses

  1. In the AppGobalResources folder of the webapplication (in the inetpub)
    1. Useable from .aspx pages –> Text=”<%$Resources:<Resource file name>, <StringId>%>”
    2. Useable from code –> HttpContext.GetGlobalResourceObject(“<Resource file name>”, “<StringId>”)
  2. In the ~SharePointRoot/Resources folder
    1. Useable from your feature (feature.xml, elements.xml, etc.) (if the Default Resource File is set on the feature) –> $Resources:<StringId>
    2. Usable from code –> SPUtility.GetLocalizedString(“$Resources:<Resource file name>”, “<StringId>”, SPContext.Current.Web.Language)
  3. In the ~SharePointRoot/CONFIG/AdminResources folder
    1. Usable from .aspx pages on Central Administration (~SharePointRoot/TEMPLATE/ADMIN/<page>.aspx)
      Note: These won’t be automatically deployed to the AppGlobalResources folder of yourCentral Administration Web Application. To do this run: stsadm -o copyappbincontent
  4. In the Resouces folder of your feature
    1. Usable from your feature (feature.xml, elements.xml, etc.) (if the Default Resource File is not set on the feature) –> $Resources:<StringId>

Note: Never start your resource files with a number! (So don’t use 2AT.. )

Unfortunately that makes it impossible to have one set of resource files for both the feature files and .aspx pages without editing the .proj or .spdata files manually. We choose to not use option four from the above list so resources are shared within a project or solution.

How do I deploy my resource files in the ~SharePointRoot/Resources folder?

Put the resource files in a new folder called Resources under the SharePointRoot SharePoint mapped folder. (Within Visual Studio 2010 you can add SharePoint mapped folders, we choose to only map the SharePointRoot folder and create the other folders as normal folders within this SharePointRoot mapped folder.) Set the ‘Default Resource File’ property on all features within the project to the name of your Resource file set.

How do I deploy my resource files in the App_GlobalResource folder of the webapplication?

  1. Create a new Module.
  2. Choose Add -> New Item.. and select Global Resources File.
  3. Select the appropriate culture and click OK.
  4. Change the Deployment Type (on the file properties) to AppGlobalResource.
  5. Repeat steps 2-4 for the other cultures.

Now you are certain that these resources will be deployed to the App_GlobalResources folder(s) when the solution is deployed to your webapplication(s).

Why a Module?

When you add a resource file to a SharePoint mapped folder you see the following property: Deployment Type.
This is set to Default and you’re not able to change this in the GUI.
When you add this file to a Module you are able to set the property to AppGlobalResource.

Last, for your information, but we choose not to use it within our SharePoint Solutions:

Add a resource file to your feature

  1. Right-click your feature and choose ‘Add Feature Resource…’.
  2. Select the appriopriate culture and click OK.
  3. Repeat these steps for the other cultures.

Now you see  to one or multiple .resx files within your feature folder. These files will be deployed to a new Resources folder within the feature folder and are only usable within your feature (feature.xml, elements.xml, etc.) (Do not set the Default Resource File property on your feature).

I hope this guide was helpfull to you, any feedback or comments are appreciated!

Advertisements

Tagged: , ,

3 thoughts on “SharePoint 2010 Solutions – Resources

  1. TuffyBook Carol E Thiago September 22, 2011 at 19:39 Reply

    Hello! my name is Carolina, and i’m also a Sharepoint Developer with a WordPress blog [http://sharepointgirl.wordpress.com]. i’m Brazilian girl, and i found your blog looking on Google about resources.
    Thanks for this post. It helped me a lot =D

  2. Radityo Ardi January 4, 2013 at 09:45 Reply

    What a simple, nice, but “DEADLY” post.
    I found it’s understandable, rather than looking at MSDN.

  3. […] For more about where and how to add resource (.resx) files in SharePoint, see my earlier post: https://carolinepoint.wordpress.com/2011/01/18/sharepoint-2010-solutions-resources/ […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: