Hi David,
I have an array I want to convert it to a CSV file and save it in the path that the user chooses.
Does the AB action have this capability or should I use js?(like PDFmake example in sample)
ThanksHi David,
I have an array I want to convert it to a CSV file and save it in the path that the user chooses.
Does the AB action have this capability or should I use js?(like PDFmake example in sample)
ThanksHello Ava,
Searching a bit I can't see any Cordova plugin that allows to the user to choose a location in order to save a file. We can see some plugins that allows to the user to choose a file, but, apparently, there is not a plugin to select a place to "save a file".
A possible approach can be to save the file in a public location, that is, instead of a private location, only available for the app. In other words, we can save the file into the root of the device's "sdcard", so we can then inform to the user in which place the file can be found: since the file is saved in a public location, the user can locate it without problems.
Certainly we can always use the appropriate Javascript, for example, the below code save a "sample.txt" file with the contents "Hello world!", in the device's "sdcard" root directory. Note how an alert dialog is shown to the user when the work end: "The file has been successfully saved at: ...":
The above Javascript code is perfectly ready to use. Additionally, the FileRead, FileWrite and FileAppend actions of App Builder has been enhanced, and now, we can specify any of the available directories in FileRead, and, a new "Directory" argument has been added to the FileWrite and FileAppend actions, to allows to specify any of the available directories.
So, if you upgrade your App Builder copy, you can do the same than the above with the enhanced FileWrite action, since this (and FileAppend) allows now to specify the "externalRootDirectory", instead to use by default the app's data directory, which is private to the user. For information about what directory to use in what platform, you must read the documentation of the Apache Cordova Files plugin.
So, in few words, replying to your question, I think the approach must be to save the CSV file in a public directory, like the "externalRootDirectory" in Android, so you can inform to the user that the CSV file has been placed in that directory, instead to ask the user where he wants the file to be saved.
Hello again,
I forget to mention one thing! All the above requires an Apache Cordova plugin. If we want as solution that works in browsers, we can take a look at this Stack Overflow thread, who, in fact, uses certain technique which allows to download a file, that is, allows the user to choose where to download a file. Unfortunately, such technique do not work in platforms like Android nor probably iOS, so, the usage of the Apache Cordova Files plugin (like explained above) is the way to do something like that for these platforms.
Hello David,
Yes, I responded with this code. also, the user can choose the location of the file:
But the problem is that it does not work for Android!
Your description was very good and useful.
Thank you for your guidance and support.
Hello Ava,
Yes; I also comment the approach (or a similar one) that you tried, but, as you said, that approach don't work in devices like Android. If your app is intended to be running in these devices and also in the browser, then you must use the right approach for the right platform, as I mentioned in my previous message.
Hello David,
I'm grateful for your assistance.
Hello David,
Following the talk of this topic ,I use this code to output CSV file:
When I run it with emulator, I get the output CSV file, but when build it to get apk for windows it dos not work!
What is problem? Can you help me that How can I get a CSV file output for Windows?
Thank you I really appreciate your help.
Hello Ava,
Yes; certainly that code don't work as expected in Android: I already mention that above in another post. For the Android platform (and probably for iOS, if you algo target this) you must use the FileWrite technique, as I explained above.
You can use the Device Cordova plugin and the Device* actions in AB to determine in which platform your app is running, so you can run the appropriate code in all the platforms that you wanted.
Hello David,
Yes, I wrote this code similar to your code but it only responds to Android not windows!
-Should I change like this?
device.platform.toLowerCase() === 'windows'
thanksHello Ava,
Are you compiling your app for the Windows platform with Apache Cordova? Or you want to run the app in browsers and also in Android? In the first case, honestly, I am not sure how the Cordova's Files plugin is supporte in Windows. In the second case, I think you must execute the Android code for the Android platform... and maybe for iOS too... and the other code for the browsers.
yes I am compiling my app for the Windows platform!
I want that user can get CSV file from my Windows app.
Hello Ava,
Are you sure that directories like "externalRootDirectory" and "documentsDirectory" are available in the Windows platform? On the other hand, your code is not very clear to me, I am sorry (maybe you can use the "code" HTML tag next time). Let me to see if tomorrow I can try the Files plugin in the Windows platform: I think that must work, but I am not sure what directory to use and if really the Files plugin works at all.
Hello David,
I'm still testing and searching,If I get a result, I will inform you. Please let us know if you have reached a result.
Thank you for your follow up and help,
Hello Ava,
Maybe you can try to compile the Files app sample for the Windows platform and see if works as expected.
Hello Ava,
We have a problem here. The Files app sample works like a charm in the Windows platform, however, this platform don't give us access to any directory outside the app storage, in other words, we can't do the same than in Android and iOS, in which we can write a file in a public directory, ready to be located by the user. I also try the "link technique" (which works in browsers) in the Windows platform, and, confirm that do not work in this platform.
The only way that I see it working implied the usage of an app's server. Yes; we can use the "OpenWindow" to give to the user the ability to download a file. The "trick" is to use the use in our app (check the right checkbox in the app's options dialog) the Cordova "Browser" plugin, and, specify "_system" for the "OpenWindow" action's "target" argument. Doing that a browser window is opened (outside our app) pointed to the right file URL.
Please, go ahead if you have any further question.
Hello David,
Thank you for your good help, If I want use "FileWrite" Actions, can I get CSV file? like this:
FileWrite "dataDirectory" "File.csv" "[my_array]" "ErrorCallback" "SuccessCallback"
Is it true?thanks
Hello Ava,
Yes; you can try the Files app sample of AB in the Windows platform: they work like expected.
Hello David,
Thanks a lot, I have this cod but I can not get CSV file in windows APK!
FileWrite "dataDirectory" "File.csv" "[arr]" "ErrorCallback" "SuccessCallback"
--[arr] is my array that have row of csv file:
StartJS
window.App.RootScope.arr = [];
EndJS
-what is the problem?Thanks a million,
Hello Ava,
I am a bit confused, since you refer to a windows APK... but the Windows platform doens't have APKs... when we talk of APKs we are talking about the Android platform. Anyway, maybe the problem is that you cannot specify the Array directly in order to be written.
If you plain to use the FileWrite action, you can prepare an string, instead of an Array: that string can contains any lines and any separated comman values in every line. Then you can save that string in the file using the FileWrite action.
Hello Ava,
Here is a sample of how to prepare an string to be used with the FileWrite action:
Using AB actions:
Using Javascript code:
Hello David,
Excuse me, I mean, the Windows platform, Thank you for your very good description.
-How to find the path that the file is stored and display to the user?
-What is the default path to save files in Windows better(dataDirectory/ cacheDirectory/ externalApplicationStorageDirectory/ externalDataDirectory/ tempDirectory/ syncedDataDirectory/ documentsDirectory?
I am very thankful,
Hello Ava,
That's the point... unfortunately, and, according to the Apache Cordova's Files plugin documentation, and, if I am not wrong... Windows do not offer to us any public directory to be used. I already mention this above: the directories wich we can use in the Windows platforms are only private for the app, for that the FileWrite approach (for what you want to use it) cannot work as expected.
We have the server side approach (using the OpenWindow action), or maybe you can find an specific Apache Cordova plugin that can help in some way... maybe a plugin that allows to show a native Windows "Save file" dialog or something like that.
Everybody can read the DecSoft support forum for learning purposes, however only DecSoft customers can post new threads. Purchase one or more licenses of some DecSoft products in order to give this and other benefits.
This website uses some useful cookies to store your preferences.