Using Resource files in SharePoint 2010 and Visual Studio 2010

To deploy Resource files with SharePoint solution / package, your solution must be not SandBoxed. So if you have choose SandBoxed Solution when you have created your project in Visual Studio, you should change it. To do it complete following steps:

  1. Open Solution Explorer in Visual Studio
  2. Select your SharePoint project
  3. In “Properties” tab set “Sandboxed Solution” to FALSE

image 

Now you should create folder mapped to SharePoint Resources folder.

  1. Right click on your project in Solution Explorer
  2. “Add” –> “SharePoint Mapped Folder …”

    image
  3. Choose “Resources” and click “OK” button

    image
  4. Visual Studio will create folder Resources for you and sub folder inside it with your project title as folder name. You should delete it, because SharePoint doesn’t allow to deploy resource files inside subfolders.
  5. Right click on just created folder –> Add –> New Item
  6. Under “General” tab choose “Resources File”, rename it and click “Add”

Now you can add some entries to new resource file. When you will deploy your solution …

image

… deploying operation will automatically copy it into SharePoint Resources catalog (“C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\Resources”)

* don’t name resource file with names which have already in SharePoint Resources catalog (otherwise you can loss SharePoint default functionality)

Now you can use your resources files where you need.

Fore example in Field-schema definition you can get value following way:

DisplayName="$Resources:PMS.ContentTypes,Contact_FirstName;"

PMS.ContentTypes is a resource file name
Contact_FirstName is a key inside resource file

4 Comments

  • And make sure that you change Build action of resx file to None.

  • Hallo,

    I have also deployed resource files (resx) by this way. This work's fine, but changes will not be update. I have read that the resources must be copied to the IIS folders. How can I reach that changes to these resource files updated.

    Kind Regards

  • Use below synatx to get value of a Resource key.
    Microsoft.SharePoint.Utilities.SPUtility.GetLocalizedString("$Resources:MailFormat", "CabBooking", 1033);

    CabBooking : Resource file name.
    MailFormat : Key in resource file.

  • Hi there, just became alert to your blog through Google,
    and found that it is really informative. I am going to
    watch out for brussels. I will be grateful if you continue this in future.
    Numerous people will be benefited from your writing.
    Cheers!

Comments have been disabled for this content.