Instead of reading the file to the console, read the file into the FlashText.Text with something (maybe at line 6) like:
System.IO.StreamReader file = new System.IO.StreamReader(filePath);
FlashText.Text = file.ReadToEnd();
file.Close();
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
Here is an example using a label and two buttons
using System;
using System.IO;
using System.Windows.Forms;
namespace WindowsFormsApplication1 {
public partial class Form1 : Form {
String[] theText;
int position = 0;
public Form1() {
InitializeComponent();
theText = File.ReadAllLines(@"D:\My Workspaces\Windows Phone 7 Solution\SimpleFlashCard\EnglishFlashCard.txt");
if (theText.Length < 1) throw new FileLoadException("There is nothing in the file!");
}
private void BackButton_Click(object sender, EventArgs e) {
Move(Direction.Backward);
}
private void NextButton_Click(object sender, EventArgs e) {
Move(Direction.Forward);
}
private void Move(Direction d) {
switch (d) {
case Direction.Backward:
position--;
if (position < 0) position = 0;
break;
case Direction.Forward:
position++;
if (position >= theText.Length) position = theText.Length - 1;
break;
}
label1.Text = theText[position];
}
private enum Direction {
Forward,
Backward
}
}
}
Momerath
Nearly a Senior Poster
3,384 posts since Aug 2010
Reputation Points: 1,232
Solved Threads: 558
While I'm trying your solution, it's show an error on the code. There are an error under the 'ReadAllLines' line, "'System.IO.File' does not contain a definition for 'ReadAllLines'.
What version of .NET are you using as it is there File.ReadAllLines
Momerath
Nearly a Senior Poster
3,384 posts since Aug 2010
Reputation Points: 1,232
Solved Threads: 558
I am using Microsoft Visual Studio 2010 Express for Windows Phone and .Net 4.0 Framework.
Windows Phone version is closer to Silverlight and does not have support for the static File.Read.. methods. See here.
You will have to use a TextReader, StreamReader or FileStream to execute the reads long hand in code.
The best of those is probably the TextReader, using the ReadLine method in a loop until you reach the end of the file.
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
That is because MS Phone only supports a subset of the Environment.SpecialFolder values. See here.
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187