
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
1096
|
Chapter 20: Toolbox
See Also
See the “Message Class” and “MessageQueue Class” topics in the MSDN documen-
tation.
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 pro-
vided for your programming convenience.
See Also
See the “Version Class” and “Version.ToString Method” topics in the MSDN
documentation.