user3530012
user3530012

Reputation: 740

C# SpecialFolders enumeration does not include Libraries Folder

The question title is seemingly straight forward and self-explanatory. The issue is that the SpecialFolders enumeration does not include Libraries Folder and I really need to access it and display its folders in a ListBox. Is there any way to do this please?

Upvotes: 0

Views: 329

Answers (1)

khellang
khellang

Reputation: 18112

The path to the Libraries folder is %APPDATA%\Microsoft\Windows\Libraries, you can use SpecialFolder.ApplicationData, which on Windows is the same as the %APPDATA% environment variable:

var appData = Environment.GetFolderPath(
        Environment.SpecialFolder.ApplicationData);

var librariesFolder = Path.Combine(appData, @"Microsoft\Windows\Libraries");

Another way to get the full path is to just expand the environment variable:

var librariesFolder = Environment.ExpandEnvironmentVariables(
        @"%APPDATA%\Microsoft\Windows\Libraries");

Anyways, this is Windows specific and won't work on other platforms, which is pretty much the single good reason to use Environment.SpecialFolder in the first place.

Upvotes: 3

Related Questions