How To Write/Read to/from an External File


This sample will show you how to write/read to and from an external file on the device. 

In the attached survey we have implemented the following (The survey can be downloaded from the link at the bottom of the article):

  1. When the answer is 'Yes' (Q1) we use the WriteFileText() function, writing to the file 2 lines, we used the second overload which also adds the file as an attachment to the interview.
  2. If we call the ReadFileText() function too soon after the Write function the file might not close fast enough so we added an empty question (Q2) to make sure the file is closed first.                  Please note: you can use the 'OnWriteFileTextResult(inFileName, inSuccess, inAppended)' function to know when the writing is finished.  
  3. Then we added an expression question (Q3) that calls in the Answer Tab the ReadFileText() function to read the text in the file. This function needs the callback function which holds a code in our case it sets the text in the file to Q5
  4. Q4 is the same as Q2 an extra question that will let the function finish reading from the file.
  5. Q5 an Open Ended question that will show the text that was written to the file. 

Please click here to learn how to import the survey. 

That's It !


Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request



Please sign in to leave a comment.