none
How to detect whether we are in WSS or MOSS programmatically RRS feed

  • Question

  • Is there a way to get whether a web part is running on top of WSS or MOSS? I'm looking for a SharePoint API to do so.

     

    If there's no API to do that, then I can look at the registry or installed programs or any other method, but wanted to make sure I didn't miss an existing API that acomplishes that.

     

    tks -Ariel

    • Edited by Mike Walsh FIN Monday, March 30, 2009 5:10 PM programmatically added to subject
    Wednesday, September 19, 2007 9:21 PM

Answers

  • Here is a simpler algorithm....

    bool isMoss = false;
    SPFeatureDefinition mossFeature = spContext.Site.WebApplication.Farm.FeatureDefinitions["OssNavigation"];
    if (mossFeature != null)
      isMoss = true;

    ...where OssNavigation is a feature that is only in MOSS.

    Too bad there isn't an API property on the SPSite object.
    Sunday, September 30, 2007 7:48 AM

All replies

  • I would guess that there is a feature for the MOSS version, check the features folder for the name of the feature, or the GUID.  Then in the web part code, you can check and see if it is turned on:

     

    You can loop through the web's features and see if the GUID exists:

     

    Code Snippet

    foreach (SPFeature feature in SPContext.Current.WebFeatures)

    {

      if (feature.DefinitionId == "YOUR GUID")

      {

         //YES, I am in MOSS mode.

      }

    }

     

     

     

     

     

    Friday, September 21, 2007 4:43 AM
  • Thanks DKeeling for your idea. As long as SP features distribution in WSS or MOSS remain stable, below should work. Also, check should be made against the exact Feature it's critical for the implementation to count on. I arbitrarilly chose those shown in the code.

     

    Code Snippet

    public enum SPPlatform

    {

      WSS,

      MOSS,

      Unknown

    }

    public static SPPlatform GetSPPlatform(SPWeb w)

    {

      Guid wssFeatureGuid = new Guid("00bfea71-c796-4402-9f2f-0eb9a6e71b18"); // WebPageLibrary

      Guid mossFeatureGuid = new Guid("29d85c25-170c-4df9-a641-12db0b9d4130"); //TransMgmtLib

      SPPlatform platform = SPPlatform.Unknown;

      foreach (SPFeature f in SPContext.GetContext(w).WebFeatures)

      {

        if (platform == SPPlatform.Unknown && f.DefinitionId.Equals(wssFeatureGuid))

        {

          platform = SPPlatform.WSS;

        }

        if ((platform == SPPlatform.Unknown || platform == SPPlatform.WSS) && f.DefinitionId.Equals(mossFeatureGuid))

        {

          platform = SPPlatform.MOSS;

        }

      }

      return (platform);

    }

     

    Tuesday, September 25, 2007 11:43 PM
  • Here is a simpler algorithm....

    bool isMoss = false;
    SPFeatureDefinition mossFeature = spContext.Site.WebApplication.Farm.FeatureDefinitions["OssNavigation"];
    if (mossFeature != null)
      isMoss = true;

    ...where OssNavigation is a feature that is only in MOSS.

    Too bad there isn't an API property on the SPSite object.
    Sunday, September 30, 2007 7:48 AM
  • I am a huge fan of "simpler".  Unfortunately, it's not always better.

    TechNet offers a couple of articles which are relevant to this discussion, and a method of detecting the installed SharePoint version is suggested:

    So the sample code would look like the following:

            public static bool IsMossInstalled

            {

                get

                {

                    string name = String.Empty;

     

                    if (SystemCheck.OSPlatform == DeployPlatform.X86)

                    {

                        name = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OSERVER";

                    }

                    else

                    {

                        name = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\OSERVER";

                    }

     

                    RegistryKey key = Registry.LocalMachine.OpenSubKey(name);

                    if (key != null)

                    {

                        string versionStr = key.GetValue("DisplayVersion") as string;

                        if (versionStr != null)

                        {

                            Version buildVersion = new Version(versionStr);

                            if (buildVersion.Major >= 12)

                            {

                                return true;

                            }

                        }

                    }

     

                    return false;

                }

            }

    The solution for WSS looks slightly different, but you get the general idea.

    FYI...


    Ross is a .NET developer based in Ottawa, Canada, working for Cactus Commerce with Microsoft.
    • Proposed as answer by Ross Holder Friday, January 9, 2009 5:12 PM
    Friday, January 9, 2009 5:04 PM
  • hmm, so how would you detect WSS?
    Monday, March 30, 2009 4:46 PM
  • Note that we have come across WSS installations with the OssNavigation feature installed as it comes bundled with Microsoft Search Server 2008 Express

    As a result our fantastic MOSS detection feature failed.

    Blogged about it here

    Wednesday, May 13, 2009 5:01 PM