Click here to Skip to main content
15,116,815 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a text file that is within the code folder so it moves around with the code and i want to read everything in it and output it into and array here what i have so far but it doesn't seem to work i have already sent them to the output directory

This is an image of where the text file is located the file is Negative.txt[^]

What I have tried:

String strAppPath = Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
            String strFilePath = Path.Combine(strAppPath, "Words");
            String strFullFilename = Path.Combine(strFilePath, "Negative.text");

            string[] Negative_Words = File.ReadLines(strFullFilename).ToArray();
            string toDisplay = string.Join(Environment.NewLine, Negative_Words);
Updated 23-Oct-20 14:00pm
BillWoodruff 23-Oct-20 22:42pm
"it moves around with the code" why ?

1 solution

I suggest embedding the file into your app as a text resource (rather than deploying it as a file that's read at run-time). See the answer to this SO question:

c# - How to embed a text file in a .NET assembly? - Stack Overflow[^]


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