I am looking forward to working on my applications with simple text files. Something very simple, place a button and a TextBox
.
The TextBox
will show the content of the .txt and the button will give the instruction to load it.
I work with Visual Studio and with the C # language.
Now, I managed to do this that I have the following code:
private void btnShowTxt_Click(object sender, EventArgs e)
{
string texto = File.ReadAllText("test.txt");
txtShowTxt.Text = texto;
}
The problem is that I noticed that if the test.txt file is not found in the path specified by Visual Studio, it generates an exception. What I want is that, whoever has my application, can read from the path that I place in the code, load in TextBox
the content of the text file.
For example, the user places the file "test.txt" in Documents or moves it to Desktop, it does not matter. I do not know why Visual Studio generates the exception if the file is not found inside the project folder.