Read a local text file

Just starting out? Need help? Post your questions and find answers here.
Ajm
Posts: 31
Joined: Wed Aug 26, 2015 1:52 pm

Read a local text file

Post 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
Regards

Andy
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Read a local text file

Post 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
Ajm
Posts: 31
Joined: Wed Aug 26, 2015 1:52 pm

Re: Read a local text file

Post by Ajm »

Thank you Peter. It works perfectly.

Regards

Andy
Regards

Andy
Fred
Site Admin
Posts: 1820
Joined: Mon Feb 24, 2014 10:51 am

Re: Read a local text file

Post by Fred »

I will try to add the file library for the next version to be able to do it natively.
Ajm
Posts: 31
Joined: Wed Aug 26, 2015 1:52 pm

Re: Read a local text file

Post by Ajm »

That will be great Fred.
Regards

Andy
Post Reply