I have been trying to get the writeTextFile command to work. But I keep getting this same error.
(I have gotten other commands like exist and create to work.)
This is the error message I get:
fs.writeTextFile not allowed. Command not found
I have been using this code to do so. (I have tried many variations.)
await JSRuntime.InvokeVoidAsync("__TAURI__.core.invoke", "plugin:fs|writeTextFile", new Dictionary<string, object>()
{
{ "path", @"C:\Users\<MyUser>\Downloads\hello.txt" }, // Full absolute path
{ "contents", "Hello World!" }, // File content
});
<Project>/src-tauri/capabilities/default.json
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
"core:default",
"opener:default",
"fs:default",
"fs:read-all",
"fs:write-all",
{
"identifier": "fs:scope",
"allow": [{ "path": "**/*" }]
}
]
}
tauri info
[✔] Environment
- OS: Windows 10.0.26100 x86_64 (X64)
✔ WebView2: 133.0.3065.69
✔ MSVC: Visual Studio Community 2022
✔ rustc: 1.84.1 (e71f9a9a9 2025-01-27)
✔ cargo: 1.84.1 (66221abde 2024-11-19)
✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
- node: 23.7.0
- npm: 10.9.2
[-] Packages
- tauri 🦀: 2.2.5
- tauri-build 🦀: 2.0.5
- wry 🦀: 0.48.1
- tao 🦀: 0.31.1
- tauri-cli 🦀: 2.2.7
[-] Plugins
- tauri-plugin-opener 🦀: 2.2.5
- tauri-plugin-fs 🦀: 2.2.0
[-] App
- build-type: bundle
- CSP: unset
- frontendDist: ../dist/wwwroot
- devUrl: http://localhost:1420/