Hanny Hanny - 5 months ago 27
ASP.NET (C#) Question

Getting special folders with a dynamic folder name

I have an array of folders I'm trying to get the sizes of.

When I get my Documents directory with this method:

string desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

It works great.

But I need to be able to dynamically input the last portion of that - is that possible?

I'd like to be able to call something like:

string desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.VARIABLENAME);

Where VARIABLENAME would be a name that I provide (that is an appropriate 'specialfolder' such as 'Favorites' or 'Desktop')

Can this be done?


you can use the string form of your enum...

var dir = (Environment.SpecialFolder)Enum.Parse(typeof(Environment.SpecialFolder), "Desktop");
string desktopFolder = Environment.GetFolderPath(dir);

Environment.SpecialFolder.Desktop.ToString() ==> Desktop