in

Dot Net Mafia

Group site for developer blogs dealing with (usually) .NET, SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, and other Microsoft products, as well as some discussion of general programming related concepts.

This Blog

Syndication

Archives

Corey Roth [MVP]

A SharePoint MVP bringing you the latest time saving tips for SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, MOSS 2007, ASP.NET, LINQ, and Visual Studio 2012.

Get the Path of a feature from a Feature Receiver

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

2012 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems