.NET/Mono Environment: Special Folders

As a prelude to an upcoming series of posts about porting from Windows CE to Raspbian; here’s a program that tells you the filepaths for all the special folders available on the current system.

Special folders in .NET/Mono are abstract folders that exist within the Windows architecture. They’re abstract folders because their paths may vary depending on the user running the application and the operation system. Since they’re accessed through an API their access is consistent on all operating systems and users, but the output can be different.

The Code

Below is the few lines of code used to display the filepaths.


using System;
using System.IO;

namespace FolderSelector_Display
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			var names = Enum.GetNames (typeof(Environment.SpecialFolder));
			foreach (var name in names)
			{
				Console.WriteLine
				(
					"{0} - {1}",
					name,
					Environment.GetFolderPath((Environment.SpecialFolder)Enum.Parse(typeof(Environment.SpecialFolder), name)).Replace(Environment.UserName, "%USERNAME%")
				);
			}
		}
	}
}

Example Output

Although you don’t need to know the filepaths in order to use them, if you want to check data being saved/loaded from you will. Furthermore you may want to check that the filepaths even exist on the system as some do not, see below for an example output from Raspbian:


Desktop - /home/%USERNAME%/Desktop
Programs -
MyDocuments - /home/%USERNAME%
Personal - /home/%USERNAME%
Favorites -
Startup -
Recent -
SendTo -
StartMenu -
MyMusic - /home/%USERNAME%/Music
MyVideos - /home/%USERNAME%/Videos
DesktopDirectory - /home/%USERNAME%/Desktop
MyComputer -
NetworkShortcuts -
Fonts - /home/%USERNAME%/.fonts
Templates - /home/%USERNAME%/Templates
CommonStartMenu -
CommonPrograms -
CommonStartup -
CommonDesktopDirectory -
ApplicationData - /home/%USERNAME%/.config
PrinterShortcuts -
LocalApplicationData - /home/%USERNAME%/.local/share
InternetCache -
Cookies -
History -
CommonApplicationData - /usr/share
Windows -
System -
ProgramFiles -
MyPictures - /home/%USERNAME%/Pictures
UserProfile - /home/%USERNAME%
SystemX86 -
ProgramFilesX86 -
CommonProgramFiles -
CommonProgramFilesX86 -
CommonTemplates - /usr/share/templates
CommonDocuments -
CommonAdminTools -
AdminTools -
CommonMusic -
CommonPictures -
CommonVideos -
Resources -
LocalizedResources -
CommonOemLinks -
CDBurning -
Advertisements

One thought on “.NET/Mono Environment: Special Folders

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s