Read text file and show to textbox

Posted by Babyeney under C# on 8/29/2011 | Points: 10 | Views : 13281 | Status : [Member] | Replies : 3
Hi, I'm currently making a game in Windows Mobile 6 SDK (C#), and I want to save top 3 high scores in text file. I have a text file and I want to read the file and display it in a textbox. So far, this is what I've done but when I tried to run it, nothing happens in the textbox.

FileStream st1 = new FileStream(@"E:\ScoreTop1.txt", FileMode.Open, FileAccess.Read);
FileStream st2 = new FileStream(@"E:\ScoreTop2.txt", FileMode.Open, FileAccess.Read);
FileStream st3 = new FileStream(@"E:\ScoreTop3.txt", FileMode.Open, FileAccess.Read);

StreamReader SR1 = new StreamReader(st1);
StreamReader SR2 = new StreamReader(st2);
StreamReader SR3 = new StreamReader(st3);

txtTop1.Text = SR1.ReadLine();
txtTop2.Text = SR2.ReadLine();
txttop3.Text = SR3.ReadLine();

I would highly appreciate your responses! Thank you!




Responses

Posted by: Vforvijay on: 8/29/2011 [Member] Starter | Points: 25

Up
0
Down
hi..Try this below link.........
http://vbdotnetaddict.blogspot.com/2011/01/read-your-file-from-your-harddisk-and.html

Babyeney, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Babyeney on: 8/29/2011 [Member] Starter | Points: 25

Up
0
Down
I need c# and the link you gave me is written in VB. But anyway thanks! I think I've done that way too, but it doesn't make any changes :( Still nothing happens to the textbox. I've tried several and different ways on reading a file and display it on a textbox, but nothing worked.

Babyeney, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 9/2/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Try this Code it's Working . . .


 string FilePath;

FilePath = txtBoxInput.Text;
if (File.Exists(FilePath))
{
textBoxContents.Text = File.ReadAllText(FilePath);
}
else
{
Response.Write("<script language='javascript'>window.alert('File not found');</script>");
}


Best Regard's
Prabhakar

Babyeney, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response