I am trying to read a text file that is currently in my project resources and display it on my windows application pop up. This is what I got so far
private void MyWindow_Load(object sender, EventArgs e)
{
string myTxt = System.IO.File.ReadAllText("myText.txt");Console.WriteLine(myTxt); }
private void button1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e){
Environment.Exit(1);
}

VulpesRank #55 · 29.2K reputationPosted Oct 28, 2014, 3:52 PM EDT
VulpesRank #55 · 29.2K reputationPosted Oct 21, 2014, 9:10 AM EDT
However, MessageBox.Show(myTxt) should work if it's a valid file path and there's anything displayable in it.
VulpesRank #55 · 29.2K reputationPosted Oct 22, 2014, 7:24 AM EDT
As I said earlier, it must be finding the file OK, as no exception is being thrown.
Marc176 reputationPosted Oct 22, 2014, 3:57 AM EDT
Actually is there a way I can read an xml file in a dialogbox?
Wim SturkenboomRank #2,527 · 554 reputationPosted Oct 22, 2014, 5:31 AM EDT
Wim SturkenboomRank #2,527 · 554 reputationPosted Oct 22, 2014, 5:37 AM EDT
string path=getpath(); /* for you to get the path */
if(!path.EndsWith(Path.DirectorySeparatorChar.ToString()))
{
path += Path.DirectorySeparatorChar.ToString();
}
path += textfile;
VulpesRank #55 · 29.2K reputationPosted Oct 22, 2014, 5:43 AM EDT
// ....
However, if you need to parse the XML file then that's a different matter and the .NET framework has various tools to enable you to do that.
Marc176 reputationPosted Oct 22, 2014, 5:51 AM EDT
private void richTextBox1_textChanged(object sender, eventArgs e)
{
string text = System.IO.File.ReadAllText("myText.txt");
MessageBox.Show(text);
}
VulpesRank #55 · 29.2K reputationPosted Oct 22, 2014, 6:04 AM EDT
Marc176 reputationPosted Oct 22, 2014, 6:30 AM EDT
VulpesRank #55 · 29.2K reputationPosted Oct 22, 2014, 6:47 AM EDT
Is the MessageBox just empty or is there an exception?
Marc176 reputationPosted Oct 22, 2014, 6:56 AM EDT
VulpesRank #55 · 29.2K reputationPosted Oct 22, 2014, 7:06 AM EDT
It must be finding the file or else there'd be an exception.
If you open the file with a text editor such as notepad, is there definitely some content?
As an alternative to displaying the file in a MessageBox, you could try displaying it directly in the RTB though DON'T put this code in the TextChanged event handler because it might cause an infinite loop:
Marc176 reputationPosted Oct 22, 2014, 7:16 AM EDT
Marc176 reputationPosted Oct 22, 2014, 10:07 AM EDT
Marc176 reputationPosted Oct 28, 2014, 5:07 AM EDT
string path = "this.xml";
string text = System.IO.File.ReadAllText(path);
Console.WriteLine(text);
I am just practicing on a console application now and not on the windows form as before.