An open API service indexing awesome lists of open source software.

https://github.com/ogunerkutay/windows-app-data-storage-guidelines


https://github.com/ogunerkutay/windows-app-data-storage-guidelines

Last synced: 7 days ago
JSON representation

Awesome Lists containing this project

README

          

# đź“‚ Windows App Data Storage Guidelines

A quick reference for where to store **application files** on Windows.
Following these conventions keeps apps clean, avoids permission issues, and aligns with industry standards.

---

## đź—‚ Key Directories

| Folder | Usage | Access |
|--------|-------|--------|
| **AppData\Roaming** | User-specific **settings, configs, small data** that should move with the user across domain PCs. | `%APPDATA%` → `C:\Users\\AppData\Roaming` |
| **AppData\Local** | User-specific **non-roaming data**, like caches, logs, temp DBs. Stays on that PC. | `%LOCALAPPDATA%` → `C:\Users\\AppData\Local` |
| **AppData\Local\Temp** | Short-lived, disposable files. OS may auto-delete. | `%TEMP%` → `C:\Users\\AppData\Local\Temp` |
| **ProgramData** | Machine-wide, non-user-specific data. Shared configs, DBs, license info. | `%PROGRAMDATA%` → `C:\ProgramData` |
| **Documents** | Files visible to the user (documents, projects). | `%USERPROFILE%\Documents` |
| **Registry** | Small settings, app state, licensing keys. | `HKCU\Software\` (per-user)
`HKLM\Software\` (machine-wide) |

---

## 🔑 Rules of Thumb

- **Settings / Configs → Roaming**
- **Cache / Logs / Big Files → Local**
- **Shared Data → ProgramData**
- **User Documents → Documents**
- **Temporary Files → Temp**
- **Small Key-Values → Registry**

❌ Never write to `Program Files` at runtime (requires admin & breaks UAC rules).

---

📌 Example App File Layout

![Layout](https://github.com/user-attachments/assets/1623be38-c569-49a1-aa59-6e0ab057ffe4)

---

## đź›  Accessing Paths in .NET (C#)

```csharp
// User-specific folders
string roaming = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string local = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string temp = Path.GetTempPath();

// Example usage
string settingsPath = Path.Combine(roaming, "MyApp", "settings.json");
string cacheFolder = Path.Combine(local, "MyApp", "cache");
✅ Always use Environment.SpecialFolder — don’t hardcode paths.

âś… Best Practices
Respect Windows conventions (don’t confuse roaming/local).

Store only what’s necessary (avoid bloat in roaming).

Use registry only for small configs, not data storage.

Clean up temp files after use.

Use installer/project setup to create default directories.

đź“– Quick mental model:

Roaming = “Settings I want everywhere”

Local = “Stuff that belongs only to this PC”

Temp = “Safe to throw away”

ProgramData = “Shared across users”

Registry = “Tiny key/value pairs”