There are two problems here: the first is that a treeview is not a "flat" display, it can have branches, and the branches can have twigs:
A
|\
| B
| |\
| | C
| D
| \
| E
F
So a simple loop is not a practical way to access all the nodes for storage. It's a recursive data structure, so you need to think about a recursive method to access it all correctly.
The second is a load bigger: a flat data file like a text document is not a good "fit" for recursive data! It's easy to store, but how do you read it back later to reconstruct the original tree based view? And without that ability, you are wasting your time storing the data at all: if you cant read it where is the point?
What I';d suggest is that you look at one of three storage methods: XML data, JSON data, and a relational database. They all have advantages and disadvantages, and which one you should probably chose will depend on how you intend to use the data and what you ne3ed to do with it once you have stored it.
But to be honest, you are probably doing this the wrong way round: designing your data storage based on how you are displaying it is almost certainly a mistake; data is far too important to leave to consider last!