Note: with the new File component, which has been introduced in release nb133 on May, 18th 2014, this workaround is now obsolete. Thank you MIT!
Scott already found a solution to read a text file and display it using a trick to echo a file's
contents from App Inventor to a php server and back.
The example reads the text file import.txt which is stored as asset in App Inventor and displays its content in a label. The text was created using the text generator at www.lipsum.com.
There is one special thing to consider for HTML documents uploaded as assets into App Inventor: During development, you have to use the development path to the embedded HTML document.
Before packaging the app, use the production path.
Phantomfoot's modification of this example which imports a XML file you can find here.
You also might be interested in the following example: How to import a multiline csv file on first run of the app.
<!DOCTYPE HTML> <html> <head> <meta name="author" content="puravidaapps.com"> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Read File</title> </head> <body>
<script> // the filename is hardcoded to be able to read a textfile stored as asset in App Inventor var strFilename = "import.txt"; xmlhttp=new XMLHttpRequest(); xmlhttp.open("GET",strFilename,false); xmlhttp.send(); xmlDoc=xmlhttp.responseText; // print the result to the page title window.document.title= xmlDoc; </script>
The limit to import a text file is around 2 MB (max. length of an URI).
Developing and maintaining snippets, tutorials and extensions for App Inventor takes a lot of time.
I hope it saved some of your time. If yes, then you might consider to donate a small amount!
or donate some mBTC to Address:
Thank you! Taifun
This work by Pura Vida Apps is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
with attribution (name=Pura Vida Apps and link to the source site) required.