Blog Home  Home Feed your aggregator (RSS 2.0)  
Peter Nowaks Mobile Blog - Reading Environment Variables and additional Environment.SpecialFolder settings from .NET CF
Windows Phone in the cloud
 
 Friday, July 10, 2009

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");

}

Friday, July 10, 2009 8:14:42 AM (W. Europe Standard Time, UTC+01:00)  #    Comments [0]   .NET Compact Framework | P/Invoke  |  Trackback
All comments require the approval of the site owner before being displayed.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, blockquote@cite, em, strike, strong, sub, sup, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview
Copyright © 2010 Peter Nowak. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.