Recipe20.5.Finding the Path to the Current Framework Version


Recipe 20.5. Finding the Path to the Current Framework Version

Problem

You need the path to where the version of the .NET Framework you are running on is located.

Solution

Use the GetruntimeDirectoryRuntimeDirectory method (implemented in System.Runtime.InteropServices.RuntimeEnvironment) to return the full path to the folder that the current version of .NET is installed in:

 public static string GetCurrentFrameworkPath() {      return System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(); } 

Discussion

There are many reasons why you might want to know the current framework path, including:

  • Manually loading the configuration files in the config directory to check settings

  • Dynamically adding references for system components in a code generator

The list could go on and on. Since the method to get to the path is pretty far down a namespace chain (System.Runtime.InteropServices.RuntimeEnvironment), it is provided for your programming convenience.

See Also

See the "Version Class" and "Version.ToString Method" topics in the MSDN documentation.



C# Cookbook
Secure Programming Cookbook for C and C++: Recipes for Cryptography, Authentication, Input Validation & More
ISBN: 0596003943
EAN: 2147483647
Year: 2004
Pages: 424

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net