SharePoint 2007: Accessing information on the SharePoint Web Server Extensions folder
Information on SharePoint and the path where it manages its information can be found in the registry. For example the registry entry SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\Location contains the path to the Web Server Extensions folder for SharePoint 2007, and SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\Version contains the current version of SharePoint 2007. Yes I know, RTM is out, and I'm still running on Beta 2 TR:-(
I came accross the following code by Microsoft for getting the Features folder:
private string GetSharePointFeaturesDirectory() { string key = @"SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0"; string name = "Location";<span style="color: rgb(0,0,255)">string</span> featuresDir = <span style="color: rgb(0,128,128)">String</span>.Empty; <span style="color: rgb(0,0,255)">try
{ RegistryKey regKey = Registry.LocalMachine.OpenSubKey(key); string value = regKey.GetValue(name) as string; regKey.Close();
featuresDir = <span style="color: rgb(0,128,128)">Path</span>.Combine(value, <span style="color: rgb(128,0,0)">@"template\features"</span>); } <span style="color: rgb(0,0,255)">catch</span> (<span style="color: rgb(0,128,128)">SecurityException</span>) { featuresDir = <span style="color: rgb(0,128,128)">String</span>.Empty; } <span style="color: rgb(0,0,255)">catch</span> (<span style="color: rgb(0,128,128)">ArgumentNullException</span>) { featuresDir = <span style="color: rgb(0,128,128)">String</span>.Empty; } <span style="color: rgb(0,0,255)">catch</span> (<span style="color: rgb(0,128,128)">ArgumentException</span>) { featuresDir = <span style="color: rgb(0,128,128)">String</span>.Empty; } <span style="color: rgb(0,0,255)">catch</span> (<span style="color: rgb(0,128,128)">ObjectDisposedException</span>) { featuresDir = <span style="color: rgb(0,128,128)">String</span>.Empty; } <span style="color: rgb(0,0,255)">catch</span> (<span style="color: rgb(0,128,128)">IOException</span>) { featuresDir = <span style="color: rgb(0,128,128)">String</span>.Empty; } <span style="color: rgb(0,0,255)">catch</span> (<span style="color: rgb(0,128,128)">UnauthorizedAccessException</span>) { featuresDir = <span style="color: rgb(0,128,128)">String</span>.Empty; } <span style="color: rgb(0,0,255)">return</span> featuresDir; }