Page 1 of 1
Read a local text file
Posted: Wed Dec 16, 2015 9:24 am
by Ajm
Hi,
Does anyone know if it is possible to read a local text file chosen with the filerequester and populate a listview with its contents?
Regards
Andy
Re: Read a local text file
Posted: Wed Dec 16, 2015 10:06 am
by Peter
this one works for me (Chrome, IE, Ff):
Code: Select all
EnableExplicit
Enumeration
#myWindow
#myButton
#myEditor
EndEnumeration
Global EditorGadgetID
! $('<div style="width:0px;height:0px;overflow:hidden"><input name="upload" type="file" id="fileinput"/></div>').appendTo($('body'));
! document.getElementById('fileinput').addEventListener('change', readTextFile, false);
! function readTextFile(e) {
! var file = e.target.files[0];
! if (!file) return;
! var reader = new FileReader();
! reader.onload = function(e) {
! v_editorgadgetid.SetGadgetText(e.target.result);
! };
! reader.readAsText(file);
! }
Procedure myButtonEvent()
! $('#fileinput').trigger('click');
EndProcedure
OpenWindow(#myWindow, 100, 100, 400, 400, "")
ButtonGadget(#myButton, 10, 10, 200, 30, "Open local textfile...")
EditorGadget(#myEditor, 10, 50, WindowWidth(#myWindow) - 20, WindowHeight(#myWindow) - 60)
EditorGadgetID = GadgetID(#myEditor)
BindGadgetEvent(#myButton, @myButtonEvent())
Greetings ... Peter
Re: Read a local text file
Posted: Wed Dec 16, 2015 10:36 am
by Ajm
Thank you Peter. It works perfectly.
Regards
Andy
Re: Read a local text file
Posted: Wed Dec 16, 2015 11:18 am
by Fred
I will try to add the file library for the next version to be able to do it natively.
Re: Read a local text file
Posted: Wed Dec 16, 2015 7:44 pm
by Ajm
That will be great Fred.