Get SharePoint 14 Hive directory in code

Is quite common in code, we often need to reference to “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14” aka 14 Hive directory in SharePoint 2010. I guess SharePoint had included a smart and easy way to get the value instead of developers to hard-code it.

So, the answer is SPUtility.GetGenericSetupPath

SPUtility.GetGenericSetupPath(string.Empty)
This returns C:\Program Files\Common Files\Microsoft Shared\web server extensions\14\

SPUtility.GetGenericSetupPath(“Template\\Images”)
This returns C:\Program Files\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\Images

This SharePoint Object Model actually available since MOSS 2007.

Leave a Reply

Your email address will not be published. Required fields are marked *