I want to read a text file from my local directory, I added the text file to my c# solution, so it would get copied at deployment.. but how do i open it? I’ve been searching but all the examples assume I have a C:\textfile.txt:
I tried just reading the file
if (File.Exists("testfile.txt"))
{
return true;
}
That didn’t work. Then I tried:
if (File.Exists(@"\\TextConsole\testfile.txt"))
{
return true;
}
but still wont open it.. any ideas??
Just because you added it to your solution doesn’t mean the file gets placed into your output Build directory. If you want to use relative path, make sure your TextFile is copied during build to the output directory. To do this, in solution explorer go to properties of the text file and set
Copy to Output DirectorytoAlwaysorCopy if newerThen you can use