DevExpertise » Blog Archive » Getting the Default SharePoint Installation Path

DevExpertise

Practical tips and tricks for all things .NET, SharePoint, Silverlight, InfoPath, and general application development.

Getting the Default SharePoint Installation Path

Posted by DevExpert on February 13th, 2009

If you ever worked with the SharePoint Object Model and have hard-coded the path to the root files (aka “12 Hive”) directory – there’s a better way.  Most of the time, the root files directory is located in the following folder:

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12

But what if it’s not and your code may be used on multiple systems?  It doesn’t make sense to include it in a config file, and it definitely doesn’t make sense to hard code it.  Luckily the OM ships with a handy little method: SPUtility.GetGenericSetupPath().  Let’s take a look…

SPUtility.GetGenericSetupPath(string.Empty)

Returns:

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\

 

SPUtility.GetGenericSetupPath("TEMPLATE")

Returns:

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\

 

SPUtility.GetGenericSetupPath(@"TEMPLATE\1033\STS\DOCTEMP\SMARTPGS")

Returns:

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\STS\DOCTEMP\SMARTPGS\

 

If you haven’t realized it by now, all this method does is append the parameter to the root files path, meaning you could pass it some nonsense path and it wouldn’t care:

SPUtility.GetGenericSetupPath("FAKEDIRECTORY")

Returns:

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\FAKEDIRECTORY\

 

SPUtility is a hidden gem, and contains a ton of helpful methods…take a look!

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>