Thursday, May 20, 2010

Programmatically get directory path to 12 hive in share point

In Our project recently We came across a requirement that while deployment of solution package (WSP) in the production server needed to run a feature activation code which refers some data from some Static files (Say .xml). As a good approach we had put this xml file in the 12-hive file system path of share point say ~features\MyCustomFeature\MyCustomXML.xml and in our feature activation code we referred this file path using SPUtility.GetGenericSetup method like

string myCustomFilePath = SPUtility.GetGenericSetup (“template\\features\\MyCustomFeature\\MyCustomXML.xml”);

Basically this method returns the file system path for the 12-Hive, or any of the folders beneath it. This is typically C:\Program Files\Common Files\Microsoft Shared\web server extensions\12.

One of the greatest advantages of this method is that in production servers even though usually share point is installed under c drive there may be scenarios where for better performance it could have been installed in any drive. So our code need not have to be hard coded for sharepoint installation path of server and works in all scenarios.