Include an external text document?

Greetings -

I’m in the early stages of designing a “configurator” for a family of small microcontrollers (Microchip Mega-0). A lot of device specific data has to be accessible to the program. And, at least during development, the medium has to be readily editable. Normally, I would use an external file that can be assigned to a FolderItem and read with a TextInputStream. But, I’d rather not have an external file, both to avoid copying by others and to avoid getting lost.

So, I wonder if a text file can be added to the project? XOJO does not complain about doing this, but I don’t know how to access the file contents. I am thinking of how images are handled and don’t see an obvious analog for text. Yes, I can create FolderItem for the file in its original location, but will that work in a compiled app where that file is part of the program rather than in its original location?

Many thanks
Jim Wagner
Oregon Research Electronics

insert a “build step - copy files” to your project, and specify the path to the files.
il will be included in the ressources of the app at build stage.

Thanks - I’ve never used build steps. Does that still provide access as a FolderItem after it has been copied?


Build steps allow you to copy an item into the application. You choose the destination folder.

Once the application was build, open it (or look in the build folder for windows) and open the destination folder (Resources ?)
In your code load the file using that path.

What OS are-you using ?

Is “App Data” a good location for the file ? If so, you can create it there at run time, then modify it at will during the application life time (5 minutes to … the 3rd millenium :wink:

yes using specialfolder.Resources
it is available for sure read-only.
if you need write, you should copy the file to specialfolder.ApplicationData at first launch

1 Like

Thank you Jean-Yves. That cleared up a lot. I was unable to fined “Build Steps - copy file” in the UG Build Steps documentation.

Best wishes

Capture d’écran 2021-07-27 à 20.39.23

I am having a big problem accessing the resource and understanding how it is named. Right now, i am using a chain of FolderItem.child operations to figure that out. I will be back if that does not work.

Thank you

Dim f As FolderItem = SpecialFolder.Resources.Child("myfolderoftextfiles")

Simply drag the document in the project. That will place it in Resources, just the same as a copy step.


Finally Got It!

Thank, you, Michel and Jean-Yves!

After I used the drag to project, it displayed as “DevConfig” in the project items list, but the file name in Jean Yves’ FolderItem statement required “DevConfig.txt”

Think things can proceed.

Jim Wagner
Oregon Research Electronics

The file itself is not touched. It keeps its name.

You will find it in the Resources folder after compilation.

A technique that I have used successfully, although I am not sure how kosher it is, is to simply copy a text document into a constant. It has the advantage for me of conceptual simplicity.

By definition, it cannot be modified from within the program. But, of course, as the developer you can modify the text file outside of the program and simply recopy into the program.

I have done this to include fairly substantial amounts of static data into programs. I do not know what limitations there are in terms of “size” of the constant that you are creating but I have put “fairly large” amounts of text into such a constant.

In one of my applications, this constant is 1.4 MB of text.

thanks, Robert.

I did not think of that one! It would probably work, here.


Im not sure if anyone has explicitly mentioned this but:

If you have a text file called listofnames.txt
and you drag it into the project like a bitmap or similar
a/ its part of the resources and built along with the app, but importantly
b/ In code, it can be used at runtime and debug time, exactly as if it were a string constant, whose name is the file name minus the .txt part

so in code you could

msgbox listofnames


firstname = listofnames.left(25)


arrayofnames = listofnames.split(",")

1 Like

Now, THAT is interesting! Right now, I am assigning it to a FolderItem and reading with a aTextInputStream.

Jim Wagner

Excellent idea. I regularly do that for Javascript code.

It is probably the simplest. It avoids using a stream to read the text.

Hi, Have read this item and tried the Build/copy files By puting the files in the space provided but when I build the project nothing is included in the build directory.
I think I have done what is asked by dragging the file names and directory into copyfiles1 but as I say nothing happens.
Any Ideas…?

Have sorted the problem.