Yet another interesting MSDN forum post I answered.  A user asked how they could programmatically determine the installation directory of SharePoint.  After multiple searches on the web, etc. I stumbled on the answer….read the registry!

Here is some sample code (i havent actually tested this code but the logic is sound):

using Microsoft.Win32;
...
RegistryKey masterKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Office Server\\12.0");
if (masterKey == null)
{
   Console.WriteLine ("Null Masterkey!");
}
else
{
   Console.WriteLine ("MyKey = {0}", masterKey.GetValue ("InstallPath"));
}
masterKey.Close();

 

the only issue I see here is that depending your farm (a 5 server farm for example), is if you install SharePoint in a different directory on each web front end.  In that case, depending on what server the request gets processed, you may get a different location that if you run the same request on a different WFE where the install directory was different. 

Honeslty I've never run into a case where the install directory was different on each WFE since most WFE's mirror each other, just thought I would throw it out there to you as well as the fact that it would just be bad practice to have the WFE’s use different install directories.

Another user responded to the post and said you could do it using the SPUtility class’s GetGenericSetupPath method, which seems a bit more logical and using the SharePoint API.

using Microsoft.SharePoint.Utilities;
...
string featurePath = SPUtility.GetGenericSetupPath("12");

Posted in:   Tags: , ,

Comments


March 23. 2009 17:20
home of natures
Hellow. A pleasant day to all. I am enjoy reading your website or blog. I got many ideas for my blog. Thanks for the information about this topic Programmatically Find SharePoint Installation Directory.

http://www.homeofnatures.com/http://www.homeofnatures.com/


April 29. 2009 13:24
franchise directory
Heya - Just looking through some blogengine.net blogs, seems to be a fairly nice platform, certainly better than blogger but still playing with the idea of wordpress.  Any major plus points you have found over WP at all?

Thanks

Matthew

http://www.the-franchise-shop.com/http://www.the-franchise-shop.com/


February 5. 2010 05:33
12th street cynthia vincent
Great write up - Thank you for sharing.

http://www.billionaireboyclub.info/la-denim-60s-stripe-polo-pink.phphttp://www.billionaireboyclub.info/la-denim-60s-stripe-polo-pink.php

Search Blog

Blog Roll

    OPMLDownload OPML file

    Recent Comments

    Banners

    Theme Grabber
    Disclaimer
    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2010 Tony Testa's World