Friday, September 21, 2007

SharePoint Resources, Types, Use and Deployment (Update)

For sometime I wanted to make an update to the deployment method for RESX files I proposed in a previous post. Even though there is nothing wrong with using custom jobs to deploy any file from a WSP solution to a SharePoint farm, I found about another option, which is a bit easier to implement. The code used to copy the resource files from the feature directory to the App_GlobalResources is pretty much the same, but this time not in a custom job, but directly in the feature event receiver.

SPWebApplication webApp =

this.Parent as SPWebApplication;

foreach (SPUrlZone zone in webApp.IisSettings.Keys)


// The settings of the IIS application to update

SPIisSettings oSettings = webApp.IisSettings[zone];

// Determine the source and destination path

sourcePath = string





string destPath = Path.Combine(oSettings.Path.ToString(), "App_GlobalResources");

string[] filePaths = Directory.GetFiles(sourcePath, "*.resx");

// Copy the files

foreach (string filePath in filePaths)


string fileName = Path.GetFileName(filePath);

File.Copy(filePath, Path.Combine(destPath, fileName), true);



Then use feature stapling to activate the feature every time a new site from a given configuration is created. Feature stapling allows us to create associations between a feature and specific site configuration. To find out more about feature stapling have a look at this article: