Deploy Resource Files in SharePoint…


While doing SharePoint projects definitely you will have to use resource files to well mange and localize your resources. Not like an ASP.net application SharePoint requires you to deploy resource files to different locations.

To be clear, different operations will look the resource files in two different locations(Web parts refer one location and the resource entries in a feature manifest file looks in another etc…). The two resource locations SharePoint will look into are,

1) C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\Resources\

2) The web application Virtual Directory (typically C:\inetpub\wwwroot\wss\VirtualDirectories\ {the web application port number}\App_GlobalResources\

So when we deploy a solution what typically done is coping the resource files to these locations manually.
 
How to overcome these manual steps?

Option 01

But with the VS 2010 SharePoint project templates, we have two options that we can use. One is mapped folders.

image

By adding a mapped folder for 14\Resources folder and placing your resource file inside that will automatically deploy the resource file in to the above mentioned first (1) location. But you have to copy the file manually to the (2) location.

 

Option 02

Or else VS2010 allows you to include element files to the project.

image

What you have to do is add a element file to to the project and add your resource file underneath it. Then select the resource file and set the properties as bellow.

image

OK and the second option will allow you to deploy the resource file to the application Virtual directory (2), but not to the SharePoint resource folder (1).

 

Option 03 – The Solution

So how to copy the file to the both locations without much effort???

If you see carefully into your VS SharePoint project, for each element, module, feature, web part etc.. has a SharePointProjectItem.spdata file an associated with it. This file is hidden when you view it from VS. By selecting the Show All Files option in solution explorer you can view these files as well.

1) Follow the above Option 02 steps (the steps that will create a element file and place the file in application virtual directly only)

2) Navigate and open the SharePointProjectItem.spdata file associated with your newly created element file

3) You will be viewing something like this

image

4) Edit the file manually and add the bellow entry to it

<ProjectItemFile Source=”MyResources.resx” Target=”Resources\” Type=”RootFile” />

5) So now it will look like,

image

 

Compile, Package the solution and try deploy. Verify the two resource locations that you expect the resource files should be. Smile

Happy Resource Deployment!!!

Advertisements

2 thoughts on “Deploy Resource Files in SharePoint…

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