Reputation: 1
I've found some code in here on how to export data from an array to a CSV file. I just have a few problems that needs to be address since I'm not very familiar with the code that I got.
listofconstraints.forEach(function(infoArray, index){
dataString = infoArray.join(",");
csvContent += dataString + "\n";
});
var encodedUri = encodeURI(csvContent);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "listofconstraints.csv");
link.click();
It works properly but it lacks some of the features that I need including, checking if the file already exists, setting the path of the file, and if it does exists, overwriting it.
Upvotes: 0
Views: 90
Reputation: 4076
JavaScript cannot exert any control over the visitor's local filesystem. Visitor remains in complete control of where downloaded files go, what they are named, and indeed whether he even wants to download them in the first place.
When you download a file from any web site, the browser asks you where you want to store the file, and if in that location there is another file named like it already then it will rename your file like file (0).csv
Upvotes: 1