I like to think of my PC’s document directory as a sacred place. As its name suggests, the documents directory is where I store my documents, in a neatly organised set of subdirectories.

It is not a dumping ground for random files and folders; this is what I use my desktop for!

I find it somewhat aggravating that so many desktop applications developers pollute the divined documents directory with their application-specific data. I hope that after reading this post, any offending developers will reconsider their choices and make better decisions on their next app.

Special Folders

Microsoft was kind enough to grace our hard drives with special folders such as My Music and My Pictures. These are just two of the 48 special directories defined in the ‘Environment.SpecialFolder‘ enum, part of the ‘System‘ namespace.

Two of my most used SpecialFolders are ‘ApplicationData’ and ‘CommonApplicationData’. ApplicationData is for application-specific data for the current roaming user, and CommonApplicationData is for application-specific data that is used by all users.

So, when you build your next fantastic desktop application, I implore you to consider using one of these special folders for your application-specific content, rather than polluting your user’s document directory. It’s super easy to use!

public void CreateApplicationSpecificGuff(string directoryName)
{
	var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
	var myAppsDataDirPath = Path.Combine(appDataPath, "MyAmazingDesktopApp");
	Directory.Create(myAppsDataDirPath);
}

How to deal with existing pollution?

When I find applications that absolutely must have their app-specific data in the document’s directory, I tend to set their directories to Hidden. Out of sight, out of mind.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.