12

We have a SDL Tridion installation on Windows Server 2008 R2. We want to get the path of the Tridion Installation home folder programatically in the Event System.

Is there an Environment Variable or setting we can read through TOM.NET API or C# code to get this?

4 Answers 4

17

You can us the below generic code to get the installation path of SDL Tridion (it looks you are using SDL Tridion 2011 as specified by the question tag) regardless of the fact whether you are using a 32-bit OS or 64-Bit OS:

      private string GetTridionInstallPath()
      {
         string output = string.Empty;
         string regKeyPath = string.Empty;
         if (Environment.Is64BitOperatingSystem)
         {
             regKeyPath = @"Software\Wow6432Node\Tridion";
         }
         else
         {
             regKeyPath = @"Software\Tridion";
         }
         RegistryKey regKey = Registry.LocalMachine.OpenSubKey(regKeyPath);
         output = regKey.GetValue("InstallDir").ToString();

         return output;
      }

I hope it helps

3
  • Thanks Pankaj for your quick reply; I will surely give it a try and let you know.
    – user427
    Commented Apr 18, 2013 at 14:05
  • 1
    This will work (I used this code regularly before, see code.google.com/p/tridion-practice/wiki/GetTridionInstallPath) but it might break between versions. Recommended to use GetTcmHomeDirectory() or %TRIDION_CM_HOME% instead.
    – Nuno Linhares
    Commented Apr 22, 2013 at 7:04
  • Thanks Nuno, for me at least, this is really valuable information that you have shared, to be very frank, I was not aware about GetTcmHomeDirectory function. I would be taking care of it in future and I totally agree, my above code would not be version proof (that why, explicitly mentioned the version as 2011 :P ) Commented Apr 22, 2013 at 9:15
11

You can use:

  • Tridion.ContentManager.ConfigurationSettings.GetTcmHomeDirectory();
  • Environment.GetEnvironmentVariable("TRIDION_CM_HOME");
  • Any of the other methods already mentioned.

If you have the option, use the GetTcmHomeDirectory() method, since that's the one used by Tridion itself.

8

I think the following environment variable will work.

%TRIDION_CM_HOME%

You can get this in C# using Environment.GetEnvironmentVariable

6

I refer you to the "GetTridionInstallPath" recipe contributed by Frank van Puffellen to the Tridion Cookbook at Tridion Practice. If you also include the comment by Peter Kjaer, it covers all the techniques mentioned here so far.

It's actually the first hit if you Google for "get tridion installation path".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.