Skip to content
Advertisement

Electron Dialog not saving the file

Electron version: 1.3.3 Operating system: Ubuntu 14.04

I want to save a XML object into a .xml file with Electron. I try this:

const {dialog} = require("electron").remote; 
dialog.showSaveDialog(myObj)

A new windows is opening, I fill the name of the file but nothing has been saving. enter image description here

Advertisement

Answer

The showSaveDialog() API does not save the file for you. You must use the returned path and use Node to save your file.

const {dialog} = require('electron').remote;
const fs = require('fs');

dialog.showSaveDialog({}).then((result) => {
  fs.writeFile(result.filePath, MyFileData, (err) => {
    // file saved or err
  });
}).catch((err) => {
  // err
});
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement