Click here to Skip to main content
14,693,599 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do i send a text file which is imported as a resource into an array. I keep getting an error saying there are illegal characters. the text file has a list of words arranged like this


I want to keep it in this same format

What I have tried:

    ArrayList AnimalList;
    String path = Resources.Animals;
    string[] Animals = null;
    Animals = File.ReadAllLines(path);
    AnimalList = new ArrayList(Animals);
catch (Exception ex)
    MessageBox.Show("Files could not be found:\n" + ex.Message);
Updated 23-Oct-20 23:20pm
Patrice T 23-Oct-20 20:27pm
Give exact error message.
vikil chandrapati 23-Oct-20 20:35pm
Illegal characters in path
Richard MacCutchan 24-Oct-20 4:18am
See my suggestion below.
Member 14732673 23-Oct-20 22:28pm
Put a couple of breakpoints in the code and step through it to find where the error occurs.

I suspect its in the File.ReadAllLines.
Something in the path has illegal characters.

ps the arrayList should be a List<t> as arraylist is not supposed to be used anymore.

Use File.ReadLines in System.IO: it returns an Array of String: [^]
I do not think that File Read will read a resource, that is most likely the cause of the error. See Working with .resx Files Programmatically | Microsoft Docs[^] for how to read resources correctly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900