As I’ve been talking in the past already, it is sometimes valuable, to create applications for the .NET CF, which are running unter the .NET Framework as well.
This can cause some issues on the .NET Framework, as you don’t have direct access to Environment variables and all enumerations from Environment.SpecialFolder when you probably need them.
But you can achieve access to this information through reflection.
For environment variables this is easy:
public static string ReadEnvironmentVariable(string variableName)
{
return (string)typeof(Environment).InvokeMember("GetEnvironmentVariable", BindingFlags.Default | BindingFlags.InvokeMethod, null, "", new object[] { variableName });
}
The same applies to the SpecialFolder-Enumeration:
public static string ReadSpecialFolder(string variableName)
{
return Environment.GetFolderPath((Environment.SpecialFolder)Enum.Parse(typeof(Environment.SpecialFolder), variableName, true));
}
Accessing both types of information is also easy. Please be aware of to do this only on the desktop system, via requesting the platform underneath:
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
string tempPath = ReadEnvironmentVariable("TEMP"));
string localApplicationDataFolder = ReadSpecialFolder("LocalApplicationData");
}