Question

How can I get the path variable very clear in a enumeration for appdata, temp and winddir? I tried this:

enter image description here

enter image description here

But the enumeration wont allow me to use a non-constant expression But I still like to have the folders clean and structured listed in an enumeration, any workarrounds for this problem?

Was it helpful?

Solution

You aren't going to be able to do that with an enum, but you could with a class:

public class MyFolder
{
    public static String Windows {get {return System.Environment.GetEnvironmentVariable("windir");}}
    public static String AppData {get {return System.Environment.GetEnvironmentVariable("appdata");}}
    public static String Temp {get {return System.Environment.GetEnvironmentVariable("temp");}}
}

I made it static so you could access like you do an enum (ie MyFolder.Windows).

OTHER TIPS

Any reason not to use

string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

etc?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top