I'm creating a small Windows Sidebar Gadget for taking notes in a simple textarea.

I have, as usual, a gadget.xml manifest file and a .html file, see below.
How is it possible to read some data / save some data in a Gadget?
I know this is usually impossible with JavaScript only (note: using localstorage is not possible because I want persistance of data), so how to save/read data inside a Windows Gadget ?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Unicode" />
<title>NeverForget</title>
<style type="text/css">
body
{
margin: 0;
width: 300px;
height: 200px;
background-color: transparent;
}
#gadgetContent
{
width: 100%;
height: 100%;
overflow: hidden;
border: none;
background-color: transparent;
}
</style>
<script type="text/jscript" language="jscript">
function init() {
// how to load notes from a file here on startup?
}
window.onkeydown = function () {
// how to save data to file?
}
</script>
</head>
<body onload="init()">
<textarea id="gadgetContent">Bonjour</textarea>
</body>
</html>
Try one of these:
There are the inbuilt methods of the System.Gadget.Settings object which can be used to to read/write from the Settings.ini file (stored in C:\Users\[user]\AppData\Local\Microsoft\Windows Sidebar) but this information will be lost if the gadget is closed or uninstalled.
Use the FileSystemObject to create or read or write folders/files anywhere. Limitation: file can only be saved as unicode or ascii.
Use an ADO Stream object to create or read or write files anywhere. Limitation: can't create folders - must be used in conjunction with the FileSystemObject. Advantage: can use any codepage that exists on your computer.
Since I like saving text files with utf-8 the example below uses the third method but you may well decide to dispense with some of the error handling. (NB - this example is based on a script published by Andrew Urquhart)
Fortunately the sidebar is able to use knownfolders and knownfolderpaths so finding the path to your documents folder for example is as easy as
Remember that the backslash is an escape character in javascript so that paths in strings must have their backslashes doubled.