DataFolder 1.1.0
dotnet add package DataFolder --version 1.1.0
NuGet\Install-Package DataFolder -Version 1.1.0
<PackageReference Include="DataFolder" Version="1.1.0" />
<PackageVersion Include="DataFolder" Version="1.1.0" />
<PackageReference Include="DataFolder" />
paket add DataFolder --version 1.1.0
#r "nuget: DataFolder, 1.1.0"
#:package DataFolder@1.1.0
#addin nuget:?package=DataFolder&version=1.1.0
#tool nuget:?package=DataFolder&version=1.1.0
DataFolder
A library that gives you a simple experience for saving user data.
Imagine this: you need to save user settings. And the routine begins:
- Creating folders by hand
- Checking for errors at every step
- Figuring out how to store the data (JSON? Binary? Your own format?)
- Writing code that has nothing to do with your actual task
DataFolder solves this problem with a simple and fast syntax.
📦 Installation
dotnet add package DataFolder
📁 Where data is stored
All data is saved into a .data folder inside the specified root path:
C:\myapp\.data\
name.txt → "Alex"
level.txt → "5"
By default, the root path is the folder where your application is running (AppContext.BaseDirectory). You can change it with SetRoot.
🚀 Quick start
using DataFolder;
var data = new DataManager();
// Make sure the .data folder exists (creates it if missing)
data.CheckDataFolder();
// Save a value
data.Set("name", "Alex");
// Read a value
string name = data.Get("name"); // "Alex"
📖 Syntax reference
Constructor
var data = new DataManager();
Creates a manager that points to .data next to your executable.
CheckDataFolder()
data.CheckDataFolder();
Creates the .data folder if it does not exist yet. Call this once before using Set / Get / Delete, unless you rely on Get(key, default, autoFile: true).
SetRoot(string rootPath)
data.SetRoot(@"C:\myapp\config");
// .data will now be created at C:\myapp\config\.data
Changes the base root. The .data subfolder is appended automatically.
Set(string key, string value)
data.Set("level", "5");
Writes value to the file named key inside .data.
Overwrites the file if it already exists.
Get(string key)
string name = data.Get("name");
Reads the value for key.
⚠️ Throws InvalidOperationException if the key does not exist.
Get(string key, string defaultValue, bool autoFile) — new in 1.1.0 ✨
// If "theme.txt" doesn't exist → create it with "dark" and return "dark"
string theme = data.Get("theme", "dark", autoFile: true);
// If "theme.txt" doesn't exist → return "dark" but DON'T create the file
string theme = data.Get("theme", "dark", autoFile: false);
Reads the value for key. If the file doesn't exist:
| autoFile | Behaviour |
|---|---|
| true | Creates the file with defaultValue and returns it. |
| false | Returns defaultValue without touching the disk. |
If the file does exist, its content is returned and defaultValue is ignored.
Delete(string key)
data.Delete("name");
Deletes the file for key.
⚠️ Throws InvalidOperationException if the key does not exist.
DeleteAll()
data.DeleteAll();
Wipes the entire .data folder and recreates it empty.
RootPath (read-only property)
Console.WriteLine(data.RootPath); // C:\myapp\.data
Returns the current absolute path to the .data folder.
💡 Examples
Storing user settings with defaults
var data = new DataManager();
data.CheckDataFolder();
string theme = data.Get("theme", "light", autoFile: true);
string volume = data.Get("volume", "50", autoFile: true);
data.Set("theme", "dark");
Switching the storage location
var data = new DataManager();
data.SetRoot(Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"MyApp"));
data.CheckDataFolder();
data.Set("token", "abc123");
📄 License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.