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):
- 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.
- 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.
- 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
- Q4 is the same as Q2 an extra question that will let the function finish reading from the file.
- 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 !
Please sign in to leave a comment.