Quote from Gaev on January 9, 2019, 4:32 amI played around with the LocalFileToVar command.
Some observations and suggestions.
a) The properties of the "fileinput obj name" named "initial-value" and "property-name" do not appear to have any significance. Each time I invoke this Button (in the Chrome Browser), it presents a FileOpen Dialog Box that shows the files in the Downloads folder (with nothing in the File Name box).
This behavior is the same as the <input type="file" name="myFile"> example in the w3schools website.
Is there any way to ...
- specify an initial folder ?
- pre-populate the File Name Box ?b) It is very important to take note of the phrase in the Help file that "loading is asynchronous"; this is similar to making get/put requests to a server (meaning that this command does NOT wait for the file content to be loaded into the specified variable). My observation was that commands coded after this command (in my case AlertBox) do not even get serviced.
You can see when the content is loaded by associating the receiving variable with a Container object.
So, I tried to use the "Watch" command ... unfortunately, I could not get the specified subroutine to be triggered.
Can there be a way of allowing the developer to specify commands to be serviced upon the completion of the LocalFileToVar event ...
- either with an event section in the Button object
- or a third parameter in the command that specifies the subroutine to be invoked (similar to AlertBox)
I played around with the LocalFileToVar command.
Some observations and suggestions.
a) The properties of the "fileinput obj name" named "initial-value" and "property-name" do not appear to have any significance. Each time I invoke this Button (in the Chrome Browser), it presents a FileOpen Dialog Box that shows the files in the Downloads folder (with nothing in the File Name box).
This behavior is the same as the <input type="file" name="myFile"> example in the w3schools website.
Is there any way to ...
- specify an initial folder ?
- pre-populate the File Name Box ?
b) It is very important to take note of the phrase in the Help file that "loading is asynchronous"; this is similar to making get/put requests to a server (meaning that this command does NOT wait for the file content to be loaded into the specified variable). My observation was that commands coded after this command (in my case AlertBox) do not even get serviced.
You can see when the content is loaded by associating the receiving variable with a Container object.
So, I tried to use the "Watch" command ... unfortunately, I could not get the specified subroutine to be triggered.
Can there be a way of allowing the developer to specify commands to be serviced upon the completion of the LocalFileToVar event ...
- either with an event section in the Button object
- or a third parameter in the command that specifies the subroutine to be invoked (similar to AlertBox)

Quote from luishp on January 9, 2019, 8:18 amHi Gaev,
For any reason, Watch command doesn't work when activated from the button, but it works fine if it is activated from Project Events or page-enter event.
Please take a look at the attached file.
Anyway, as most of the file operations are asynchronous I will try top add a new parameter to call a subroutine when finished.Thank you!
Hi Gaev,
For any reason, Watch command doesn't work when activated from the button, but it works fine if it is activated from Project Events or page-enter event.
Please take a look at the attached file.
Anyway, as most of the file operations are asynchronous I will try top add a new parameter to call a subroutine when finished.
Thank you!
Uploaded files:Quote from Gaev on January 9, 2019, 7:39 pm@luishp:
Please take a look at the attached file.
For any reason, Watch command doesn't work when activated from the button, but it works fine if it is activated from Project Events or page-enter event.
Thanks; the revised sample app worked just fine. I sent you an email about this limitation.
Anyway, as most of the file operations are asynchronous I will try top add a new parameter to call a subroutine when finished.
Thanks; this will add even more value to the product.
@luishp:
Please take a look at the attached file.
For any reason, Watch command doesn't work when activated from the button, but it works fine if it is activated from Project Events or page-enter event.
Thanks; the revised sample app worked just fine. I sent you an email about this limitation.
Anyway, as most of the file operations are asynchronous I will try top add a new parameter to call a subroutine when finished.
Thanks; this will add even more value to the product.

Quote from luishp on January 10, 2019, 7:59 amRegarding point a) please take a look at this other thread.
The property property-name is mandatory, otherwise the FileInput Object will not work.
Please take a look here.Thank you.
Regarding point a) please take a look at this other thread.
The property property-name is mandatory, otherwise the FileInput Object will not work.
Please take a look here.
Thank you.
Quote from Gaev on January 10, 2019, 5:23 pm@luishp:
Thank you, but my point was about "a possible way (via variables) to pre-set the initial Folder and File in the FileOpen Dialog Box that the user is presented with".
As I mentioned in the other post, the example on the w3schools website exhibited similar behaviour; and a Google search shows that other have asked the same question without any resolution.
It looks like it is designed to protect users from hackers; but it puzzles me why the initial folder is the Downloads one (it being the most likely candidate for hackers to download hacked files !!!).
I guess users will just have to learn to navigate to other folders :(
@luishp:
Thank you, but my point was about "a possible way (via variables) to pre-set the initial Folder and File in the FileOpen Dialog Box that the user is presented with".
As I mentioned in the other post, the example on the w3schools website exhibited similar behaviour; and a Google search shows that other have asked the same question without any resolution.
It looks like it is designed to protect users from hackers; but it puzzles me why the initial folder is the Downloads one (it being the most likely candidate for hackers to download hacked files !!!).
I guess users will just have to learn to navigate to other folders :(

Quote from rrey on December 23, 2019, 9:02 pmHola @luishp,
Estoy tratando de usar las funciones LocalFileToVar y VarToLocalFile conjuntamente para recuperar texto de un archivo, modificarlo y volverlo a grabar el el archivo. Y solo me funciona la primera vez. Una vez vuelvo a editar y grabar la variable en el archivo ya no recupera el contenido.
Te adjunto el archivo a ver si puedes ayudarme.
Gracias y que pases unas felices fiestas.
Roger Rey
Hola @luishp,
Estoy tratando de usar las funciones LocalFileToVar y VarToLocalFile conjuntamente para recuperar texto de un archivo, modificarlo y volverlo a grabar el el archivo. Y solo me funciona la primera vez. Una vez vuelvo a editar y grabar la variable en el archivo ya no recupera el contenido.
Te adjunto el archivo a ver si puedes ayudarme.
Gracias y que pases unas felices fiestas.
Roger Rey
Uploaded files:

Quote from luishp on December 24, 2019, 4:59 pmHola Roger, creo que el lío estaba con el Watch más que con LocalFileToVar y VarToLocalFile.
Echa un vistazo al archivo que adjunto y si tienes cualquier duda, me dices.
Cambiando un par de cosas, he convertido tu ejemplo en un sencillo editor de textos.
Fíjate que, además de en los botones, he puesto código en la propia página.
Saludos y felices fiestas!
Hola Roger, creo que el lío estaba con el Watch más que con LocalFileToVar y VarToLocalFile.
Echa un vistazo al archivo que adjunto y si tienes cualquier duda, me dices.
Cambiando un par de cosas, he convertido tu ejemplo en un sencillo editor de textos.
Fíjate que, además de en los botones, he puesto código en la propia página.
Saludos y felices fiestas!

Quote from rrey on December 26, 2019, 1:14 pmHola de nuevo @luishp,
Lo he probado y pasa lo mismo. La primera vez funciona, graba el texto en el archivo. Después modifico el texto lo vuelvo a grabar en el mismo archivo y cuando lo abro no se actualiza el contenido. Lo he probado muchas veces y no hay forma. Si al abrirlo das al botón cancelar y lo vuelves abrir entonces funciona. Pero no es la solución.
Saludos,
Roger Rey
Hola de nuevo @luishp,
Lo he probado y pasa lo mismo. La primera vez funciona, graba el texto en el archivo. Después modifico el texto lo vuelvo a grabar en el mismo archivo y cuando lo abro no se actualiza el contenido. Lo he probado muchas veces y no hay forma. Si al abrirlo das al botón cancelar y lo vuelves abrir entonces funciona. Pero no es la solución.
Saludos,
Roger Rey

Quote from luishp on December 27, 2019, 8:36 amHola Roger,
Creo que lo que te sucede es lo siguiente. La primera vez descargas el archivo correctamente porque no existe otro con el mismo nombre. En las sucesivas descargas el navegador detecta que ya existe un archivo con el mismo nombre y renombra el nuevo de este modo: nombre(1).txt, nombre(2).txt... para no sobre-escribir el que ya había.
Puedes configurar el navegador para que te pregunte cada vez donde deseas guardar los archivos descargados y así sobre-escribir el que ya hubiese.
Otra opción es utilizar el plugin neoPHP para guardar los archivos en el servidor.
Actualmente Chrome está desarrollando una nueva API de JavaScript que permitirá la lectura y almacenamiento de archivos locales de un modo más directo.Saludos.
Hola Roger,
Creo que lo que te sucede es lo siguiente. La primera vez descargas el archivo correctamente porque no existe otro con el mismo nombre. En las sucesivas descargas el navegador detecta que ya existe un archivo con el mismo nombre y renombra el nuevo de este modo: nombre(1).txt, nombre(2).txt... para no sobre-escribir el que ya había.
Puedes configurar el navegador para que te pregunte cada vez donde deseas guardar los archivos descargados y así sobre-escribir el que ya hubiese.
Otra opción es utilizar el plugin neoPHP para guardar los archivos en el servidor.
Actualmente Chrome está desarrollando una nueva API de JavaScript que permitirá la lectura y almacenamiento de archivos locales de un modo más directo.
Saludos.

Quote from rrey on December 29, 2019, 12:29 pmHola de nuevo @luishp ,
Es curioso pero configurando el navegador para que me pregunte donde guardar el archivo, la primera vez al abrirlo me funciona, es decir carga el contenido en la variable, pero posteriormente si modifico el contenido y lo grabo al abrirlo ya no lo hace. Es decir me pasa lo mismo que antes, solo carga el contenido de la variable la primera vez. Tengo que inicializar la aplicación para que funcione.
Saludos,
Roger Rey
Hola de nuevo @luishp ,
Es curioso pero configurando el navegador para que me pregunte donde guardar el archivo, la primera vez al abrirlo me funciona, es decir carga el contenido en la variable, pero posteriormente si modifico el contenido y lo grabo al abrirlo ya no lo hace. Es decir me pasa lo mismo que antes, solo carga el contenido de la variable la primera vez. Tengo que inicializar la aplicación para que funcione.
Saludos,
Roger Rey

Quote from luishp on December 29, 2019, 12:47 pm@rrey no consigo reproducir el problema que comentas. A mi me funciona correctamente cuando le indico que sustituya el archivo existente. Quizá puedas grabar un video mostrando lo que te sucede.
Saludos.
@rrey no consigo reproducir el problema que comentas. A mi me funciona correctamente cuando le indico que sustituya el archivo existente. Quizá puedas grabar un video mostrando lo que te sucede.
Saludos.

Quote from rrey on December 29, 2019, 1:05 pmMira @luishp el vídeo: https://youtu.be/t4FxZ5PIi-w
Gracias por tu tiempo.
Mira @luishp el vídeo: https://youtu.be/t4FxZ5PIi-w
Gracias por tu tiempo.

Quote from luishp on December 29, 2019, 6:27 pmRoger, efectivamente en Chrome no funciona bien en el segundo y sucesivos intentos.
En FireFox, con el que trabajo habitualmente, funciona perfectamente.
Echaré un vistazo a ver si hay algo que se me está pasando por alto a ver si puedo solucionarlo.
Gracias a ti por tu paciencia @rrey
Roger, efectivamente en Chrome no funciona bien en el segundo y sucesivos intentos.
En FireFox, con el que trabajo habitualmente, funciona perfectamente.
Echaré un vistazo a ver si hay algo que se me está pasando por alto a ver si puedo solucionarlo.
Gracias a ti por tu paciencia @rrey

Quote from luishp on December 29, 2019, 6:46 pm@rrey, ya se donde está el problema.
Fíjate que LocalFileToVar se ejecuta en el evento "change" del objeto FileInput1. Como tratamos de abrir dos veces seguidas el mismo archivo, no hay ningún cambio y por tanto el evento "change" no se ejecuta.
Si abres cualquier otro archivo de texto y después vuelves al que has editado y guardado, funcionará correctamente.
Lo curioso es que FireFox si lanza el evento "change" incluso aunque le pidas dos veces el mismo archivo.
Ahora toca descubrir como resetear el valor de FileInput1 sin intervención del usuario, lo cual creo que, por motivos de seguridad, no va a ser tarea sencilla.
Saludos.
@rrey, ya se donde está el problema.
Fíjate que LocalFileToVar se ejecuta en el evento "change" del objeto FileInput1. Como tratamos de abrir dos veces seguidas el mismo archivo, no hay ningún cambio y por tanto el evento "change" no se ejecuta.
Si abres cualquier otro archivo de texto y después vuelves al que has editado y guardado, funcionará correctamente.
Lo curioso es que FireFox si lanza el evento "change" incluso aunque le pidas dos veces el mismo archivo.
Ahora toca descubrir como resetear el valor de FileInput1 sin intervención del usuario, lo cual creo que, por motivos de seguridad, no va a ser tarea sencilla.
Saludos.

Quote from rrey on March 27, 2020, 7:03 pmHola @luishp ,
Hace tiempo que te comenté el tema de LocalFileToVar para recuperar un archivo local. El problema era que si abres una vez el archivo sí funciona pero la segunda vez que vuelves abrir el mismo archivo ya no funciona. Esto ya lo comprobamos. Sabes si en VisualNeo esta acción podrá funcionar bien o hay alguna otra solución. Te lo digo porque es muy necesaria para cualquier program en el que el usuario quiera recuperar datos grabados previamente en su ordenador.
Saludos cordiales,
Roger Rey
Hola @luishp ,
Hace tiempo que te comenté el tema de LocalFileToVar para recuperar un archivo local. El problema era que si abres una vez el archivo sí funciona pero la segunda vez que vuelves abrir el mismo archivo ya no funciona. Esto ya lo comprobamos. Sabes si en VisualNeo esta acción podrá funcionar bien o hay alguna otra solución. Te lo digo porque es muy necesaria para cualquier program en el que el usuario quiera recuperar datos grabados previamente en su ordenador.
Saludos cordiales,
Roger Rey

Quote from luishp on March 27, 2020, 10:31 pmHola @rrey,
Si hay solución: poniendo el botón Input File dentro de un formulario y reseteando el formulario cada vez que cargas un archivo (así vuelve a estar en blanco y detecta el cambio de archivo al elegir el mismo). A ver si mañana saco un rato y subo un ejemplo aquí.
Saludos!
Hola @rrey,
Si hay solución: poniendo el botón Input File dentro de un formulario y reseteando el formulario cada vez que cargas un archivo (así vuelve a estar en blanco y detecta el cambio de archivo al elegir el mismo). A ver si mañana saco un rato y subo un ejemplo aquí.
Saludos!

Quote from luishp on March 28, 2020, 1:28 pm@rrey aquí tienes la solución (adjunto). Como te comentaba, el truco está en resetear el File Input y para eso hay que ponerlo dentro de un formulario. Si tienes alguna duda, me dices.
Saludos!
@rrey aquí tienes la solución (adjunto). Como te comentaba, el truco está en resetear el File Input y para eso hay que ponerlo dentro de un formulario. Si tienes alguna duda, me dices.
Saludos!
