Using Resources Files in SharePoint Web Parts

  1. First you need to have your resource files. Place them directly under the project node. For Example add:
    1. MyResource.resx

      Add a new resource entry in the file:

          Key: hello

          Value: Hello

    2. MyResource.ar-sa.resx

      Add a new resource entry in the file:

          Key: hello

          Value:أهلا

    Take care that these resources files must be embedded resources.

  1. In the render function add the following code:

    ResourceManager rm = new
    ResourceManager(“projectname.MyResources”,this.GetType().Assembly);

    writer.Write(rm.GetString(“hello”));

To deploy this web part, use the regular procedure of deploying web part. But you must take care that you will need to deploy the every resources dlls in “..\bin\debug” subdirectory to the Global Assembly Cash (in” windows\assembly” directory). You will find a subdirectory for each culture you have in the project under this directory you will find a projectname.resources.dll file you have to deploy this file to the GAC.

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: