Electron Dialog saving file not working

前端 未结 2 1095
闹比i
闹比i 2021-01-14 15:43

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:

2条回答
  •  情书的邮戳
    2021-01-14 16:26

    it's recommended to use returned path from dialog.showSaveDialog to get filepath in new versions of electron: (which is result.filePath in the below code)

        filename = dialog.showSaveDialog({}
        ).then(result => {
          filename = result.filePath;
          if (filename === undefined) {
            alert('the user clicked the btn but didn\'t created a file');
            return;
          }
          fs.writeFile(filename, content, (err) => {
            if (err) {
              alert('an error ocurred with file creation ' + err.message);
              return
            }
            alert('WE CREATED YOUR FILE SUCCESFULLY');
          })
          alert('we End');
        }).catch(err => {
          alert(err)
        })
    

提交回复
热议问题