title: Get Farm Features from SharePoint 2010
body: <p>I am attempting to get a list of Farm Features from a SharePoint 2010 Central Admin site.  The issue I am having is that I have only succeeded in pulling back <strong>Site</strong> Features.  The following code is what I am currently working with: </p>
  
  <pre><code>foreach (SPFeature feature in SPAdministrationWebApplication.Local.Features)
  {
      string featureName = feature.Definition.DisplayName;
      if (featureName != null)
      {
          XElement newItem = new XElement("Item", featureName);
          infoTree.Add(newItem);
      }
  
  }
  </code></pre>
  
  <p>I have also tried using <code>SPFarm.Local.FeatureDefinitions</code>  as follows:</p>
  
  <pre><code>foreach (SPFeatureDefinition feature in SPFarm.Local.FeatureDefinitions)
  {
      string featureName = feature.DisplayName;
  if (featureName != null)
      {
          XElement newItem = new XElement("Item", featureName);
          infoTree.Add(newItem);
      }
  </code></pre>
  
  <p>but to no avail.  The next avenue I am approaching is using <code>SPFeatureCollection</code>. Is there a better approach I can take to this issue?  Basically I'm just looking for some clues as I have not gotten anything out of <code>SPFeatureCollection</code> just yet.</p>
  
  <p><strong>EDIT</strong>
  I have been messing around with </p>
  
  <pre><code>SPFeatureCollection featureCollect = SPContext.Current.Site.Features  
  </code></pre>
  
  <p>but so far I am having an issue with <code>SPContext</code> returning null.</p>