Get the Path of a feature from a Feature Receiver

Posted Thursday, January 10, 2008 10:40 AM by C-Dog's .NET Tip of the Day

The other day, I had a need to read an XML file during the FeatureActivated event of a SharePoint FeatureReceiver. I needed to know what the path of the feature was so that I could read the file. There are probably multiple ways to do this, but here is one that I stumbled upon that actually worked. I made use of the SPUtility class that has some helper methods to get paths. Here's the code.

string featurePath = string.format(@"{0}"\FEATURES\{1}", 
SPUtility.GetGenericSetupPath("Template"), 
properties.Definition.DisplayName);

That seems to work for me so far. The SPUtility class gets the path to the template folder and the DisplayName property off of Definition returns the folder name of the feature. If anyone else has a better way to do it, be sure and leave a comment.

Read the complete post at http://www.dotnettipoftheday.com/blog.aspx?id=399

Filed under: ,