Provisioning Files To A Feature's Root Folder In Sharepoint 2010

3 December 2010

I have been doing some work recently in InfoPath, and as part of investigating deployment of a custom InfoPath form to a Sharepoint installation, it was decided that we would use the not-so-well-documented XsnFeatureReceiver class in order to deploy the form to a site. However, there is a catch to using it - the .xsn must be placed in the root folder of the feature (ie 14/TEMPLATE/FEATURES/MyCustomFeature/MyForm.xsn).

I spent quite a while trying to configure a Module element to provision a file directly to the feature root folder, but Visual Studio 2010 doesn't allow you to set a blank foldername the module, which means that using a Module, you'll be stuck provisioning your files to a subfolder on your feature.

It turns out the solution to this (and the right way to include files with your features that you don't necessarily want to push to Sharepoint/content database) is using the Empty Element item.

Create an empty element and a feature as normal, and add whatever files you want to include to your EmptyElement item:

Feature File 1

Then, for each of the files, open the properties window and make sure the Deployment Type is set to ElementFile.

Feature File 2

Finally, we'll set the Path for the deployment location to nothing - unlike a module, an elementfile supports a blank path (which will then deploy the file to the feature root folder, where we want it)

Feature File 3

This should now deploy your files to the feature root folder - you can test it out by deploying the solution and examining your physical server's Sharepoint Root to confirm everything worked as expected.

Tags: features, InfoPath, SharePoint 2010

Add a Comment

No Comments