What is the best way to save data locally to a text file?

In NSBasic, I see no direct way to just save some textual data to the hard drive on a desktop computer. I know NSBasic was made for app design, but isn’t there a direct way to just save data to a file on a local desktop machine?

I’ve looked at all the docs and the closest thing I have found is using AJAX with a server - I don’t want or need to GET or POST data just yet and will NOT be using any database files.

Mike

AppStudio is based on Web technology and runs in a browser instance. One of the security features of browsers is that the pages or apps you run should not be able to mess up your computer.

That’s why they don’t allow the creation of files - you can imagine the mischief which would be possible.

Can you explain more about what you’re trying to accomplish?

I really can’t explain much in a public forum, but I need to somehow save this data either to my local computer or encrypted here in code that cannot be intercepted and then sent to a server. I don’t care if encrypted code is intercepted en route because it’s already unreadable.

Mike

So you don’t actually need to save the data in a file - you just need to save the data somehow.

Have a look at localStorage:
https://wiki.nsbasic.com/LocalStorage_made_Simple

If you only need to save your data as a text file, this works in Chrome. Does not work in Safari.

function saveContent(fileContents, fileName)  //Chrome only
   {
       var link = document.createElement('a');
       link.download = fileName;
       link.href = 'data:,' + fileContents;
       link.click();
   }  

Helen

On the local deployment is there no way to save or open a txt file on the local hard disk?

Also the htmlview can work with local files i have used

file:///xxxx filene

Is this also possible for the src of an image or picturebox?

Regards

You can read a file using ReadFile() or Ajax().

Writing a file is a bit more complicated. Browsers don’t allow you to write directly to the computer’s filesystem. (Can you imagine what problems could happen if web pages were allowed to write files to the user’s computer?)

Helen’s suggestion is a good workaround. If you’re planning to run as a native app on Android or iOS, there are plugins to do this. For the Desktop, Electron makes this possible.