SPUtility.GetGenericSetupPath is obsolete, long live SPUtility.GetCurrentGenericSetupPath & GetVersionedGenericSetupPath

Whenever you are in a scenario where you need the location to the SharePoint root directory on the server in the farm that is executing your code, do NOT hardcode the path like the example below:

Bad practice:

private const string rootfolder = "C:\\Program Files\\Common Files\\Microsoft Shared\\web server extensions\\14\\";

The location of the SharePoint root directory depends on the configuration during the installation of SharePoint, your code will break if this configuration is different.

As you probably already know, it is a recommended practice to use GetGenericSetupPath available in the static SPUtility class. Please be aware that this method is obsolete in SharePoint 2013 and we have 2 new methods:

This will help you to make sure that your code is generic enough to deal with all scenario’s. For example with site collection upgrade.

Hope it helps!

VN:F [1.9.22_1171]
Rating: 10.0/10 (2 votes cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)
SPUtility.GetGenericSetupPath is obsolete, long live SPUtility.GetCurrentGenericSetupPath & GetVersionedGenericSetupPath , 10.0 out of 10 based on 2 ratings