8 examples of 'javascript save file to specific folder' in JavaScript

Every line of 'javascript save file to specific folder' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
119function javaSaveFile(filePath,content) {
120 try {
121 if(document.applets["TiddlySaver"])
122 return document.applets["TiddlySaver"].saveFile(javaUrlToFilename(filePath),"UTF-8",content);
123 } catch(ex) {
124 }
125 try {
126 var s = new java.io.PrintStream(new java.io.FileOutputStream(javaUrlToFilename(filePath)));
127 s.print(content);
128 s.close();
129 } catch(ex) {
130 return null;
131 }
132 return true;
133}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

5export function saveFile(fileData, name) {
6 var pom = document.createElement('a');
7 pom.setAttribute('href', 'data:text/plain;charset=UTF-8,' + encodeURIComponent(fileData));
8 pom.setAttribute('download', name);
9 pom.style.display = 'none';
10 if (document.createEvent) {
11 const event = document.createEvent('MouseEvents');
12 event.initEvent('click', true, true);
13 pom.dispatchEvent(event);
14 } else {
15 pom.click();
16 }
17}
20function savePage()
21{
22 g_fileName = scriptThread.showFileDialog(true, "save terminal content", "", "");
23 if(g_fileName != "")
24 {//One file selected.
25 if(scriptFile.writeFile(g_fileName, false, UI_WebView.evaluateJavaScript("getContent()"), true))
26 {
27 scriptThread.messageBox("Critical", "error", "could not write " + g_fileName);
28 }
29 }
30}
169function saveFile (content) {
170 const fileName = dialog.showSaveDialog(mainWindow, {
171 title: 'Save HTML Output',
172 defaultPath: app.getPath('documents'),
173 filters: [
174 { name: 'HTML Files', extensions: ['html'] }
175 ]
176 })
177
178 if (!fileName) return
179
180 fs.writeFileSync(fileName, content)
181}
15function saveAs (focusedWindow) {
16 let defaultPath = focusedWindow.filePath || 'untitled.calculist'
17 dialog.showSaveDialog({defaultPath: defaultPath, properties: ['saveFile']}, function (filePath) {
18 focusedWindow.webContents.send('save', filePath)
19 focusedWindow.setDocumentEdited(false)
20 focusedWindow.filePath = filePath
21 });
22}
259function saveAs(data, filename) {
260 if(!filename) filename = 'console.json'
261
262 if (typeof data == 'object') {
263 data = JSON.stringify(data);
264 }
265
266 var blob = new Blob([data], { type: 'application/octet-stream' });
267 var url = window.URL.createObjectURL(blob);
268 var saveas = document.createElement('a');
269 saveas.href = url;
270 saveas.style.display = 'none';
271 document.body.appendChild(saveas);
272 saveas.download = filename;
273 saveas.click();
274 setTimeout(function() {
275 saveas.parentNode.removeChild(saveas);
276 }, 1000)
277 document.addEventListener('unload', function() {
278 window.URL.revokeObjectURL(url);
279 });
280}
166function saveFile()
167{
168 if ($('uploadfile').value.blank() &&
169 $('filename').value.blank())
170 {
171 alert(incompleteFields);
172 return false;
173 }
174 if ($('upload_switch').checked &&
175 !$('uploadfile').value.blank())
176 {
177 document.fb_form.submit();
178 } else {
179 FileBrowserAjax.callAsync('updatedbfileinfo',
180 $('path').value,
181 $('filename').value,
182 $('file_title').value,
183 $('file_description').value,
184 $('file_fast_url').value,
185 $('oldname').value
186 );
187 }
188}
186function save(code, name) {
187 var blob = new Blob([code], {
188 type: 'text/plain'
189 });
190 if (window.saveAs) {
191 window.saveAs(blob, name);
192 } else if (navigator.saveBlob) {
193 navigator.saveBlob(blob, name);
194 } else {
195 url = URL.createObjectURL(blob);
196 var link = document.createElement("a");
197 link.setAttribute("href", url);
198 link.setAttribute("download", name);
199 var event = document.createEvent('MouseEvents');
200 event.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
201 link.dispatchEvent(event);
202 }
203}

Related snippets