FileReader

From NSB App Studio
Revision as of 19:28, 16 November 2015 by Ghenne (talk | contribs) (Created page with "reader.readAsText() == Description == The FileReader object allows apps to read files into memory. Depending on the platform, files can be flat text, photos, movies or other...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

reader.readAsText()

Description

The FileReader object allows apps to read files into memory. Depending on the platform, files can be flat text, photos, movies or other types of files. Certain platforms restrict which files can be opened. Photo Libraries, DropBox, iCloud Drive and Google drive files can usually be opened.

The file to be opened has to be selected by the user from a TextBox control, with inputType set to File. It is not possible to hard code a file name: this is for security purposes. Otherwise, web apps would be able to open files on user's systems that should not be allowed.

The FileReader control can read files, but cannot write them.

To use this function, first create a reader object by called new FileReader.

Example

Dim reader
reader = new FileReader();

Function txtFilename_onchange()
  reader.readAsText(txtFilename.files[0])
End Function

Function reader_onload(e)
  Dim lines()
  txtData.text = ""
  txtData.text = txtData.text & "Filename: " & txtFilename.files[0].name & vbCRLF
  txtData.text = txtData.text & "Size: " & txtFilename.files[0].size & vbCRLF
  txtData.text = txtData.text & "Modified: " & txtFilename.files[0].lastModifiedDate & vbCRLF
  
  lines = Split(e.target.result, vbLF)
  txtData.text = txtData.text & "Lines: " & Len(lines) & vbCRLF
  
  For i = 0 To 50
    txtData.text = txtData.text & lines(i) & vbCRLF
  Next
  
End Function

Output

(nextAction appears 3 seconds later)

Related Items

ClearInterval, ClearTimeOut, SetInterval