Why use SPJobDefinition in SharePoint Resources deployment
Recently Matthias Glubrecht and other readers of my post SharePoint Resources, Types, Use and Deployment asked me why do I use a custom SPJobDefinition to deploy resx files to the App_GlobalResources folder. The reason is simple (I remember when I asked Vincent Rothwell the same question and he was kind to explain this to me), the event receiver events (FeatureActivated etc.) are only invoked on the server where the feature gets activated not on all farm servers.
In other words if we need to make modifications to the objects stored in the content or configuration databases of the SharePoint farm, we can use directly the event receiver event handlers. The situation is a bit different when we need to modify objects outside of the SharePoint database, such as the files system, files or the resources (resx) files. In order to invoke the update on all front-web servers need to create a custom SPJobDefinition. One exclusion of this rule is the web.config modification class, which synchronizes web application configuration files via the SharePoint DOM.
Another benefit of using SPJobDefinition is that the timer service runs with a higher privileged account, where as the event receiver event handlers are invoked in the context of the current user.
Dovizhdane!
Comments
I’ve modified your code so that it copies resx files from the feature into the App_GlobalResources folder. It works fine on a single box; however it does not propagate those changes to all the web servers.
From my understanding SPJobDefinition should create a job on all front end servers in the farm when a web application calls an update method. Essentially I would like to copy the custom resx files into App_GlobalResources folder upon feature activation in a multi web-front-end environment.
Any help or hints will be much appreciated.
Cheers
nathan
When you submit SPJobDefinition it is executed on all servers in the farm.
Here are some other consideration when using this approach [via Andrew Connell] http://www.andrewconnell.com/blog/archive/2007/07/02/6067.aspx
We used you solution to copy the resx to our Global Resources on a really big farm and it works flawless
Interesting article! What happens if we add a new WFE Server to the farm at a later date? Would the Resource files automatically get copied to it too? I believe other files within a SharePoint solution do get copied. If not, any ideas how to get around it?
Thanks.
Deepak.
My guess is that if SharePoint automatically activates all relevant features on the newly added server, this wouldn't be an issue. However I never went that far.
Mikhail