DEV Community

Cover image for Storing Desktop App Data
Mike James
Mike James

Posted on

Storing Desktop App Data

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!

Show me the code!

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

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.

Top comments (1)

Collapse
 
epsi profile image
E.R. Nurwijayadi

In linux, there are these directories.

  • .config
  • .local
  • .cache

Every app related stuff should be placed over there.