I am making an app based IO Concept .
1. First I have to Create New File and write some text in it.
2. Second I have made a button to read a file .
3. Next time when i start with this step . I should check it out that preciously any file exits or not . if exists then read and if not create new.
The 3rd thing in the introduction above is giving me problem . I am not getting how to write code for this . Please Help me if any body knows about it .
Read and Write codes i have developed and here it is
private void btnWrite_Click(object sender, RoutedEventArgs e)
{
System.IO.IsolatedStorage.IsolatedStorageFile local =
System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
if (!local.DirectoryExists("DataFolder"))
local.CreateDirectory("DataFolder");
using (var isoFileStream =
new System.IO.IsolatedStorage.IsolatedStorageFileStream(
"DataFolder\\DataFile.txt",
System.IO.FileMode.OpenOrCreate,
local))
{
using (var isoFileWriter = new System.IO.StreamWriter(isoFileStream))
{
isoFileWriter.WriteLine(this.textBox1.Text);
}
}
this.btnWrite.IsEnabled = false;
this.btnRead.IsEnabled = true;
}
private void btnRead_Click(object sender, RoutedEventArgs e)
{
System.IO.IsolatedStorage.IsolatedStorageFile local =
System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
using (var isoFileStream =
new System.IO.IsolatedStorage.IsolatedStorageFileStream
("DataFolder\\DataFile.txt", System.IO.FileMode.Open, local))
{
using (var isoFileReader = new System.IO.StreamReader(isoFileStream))
{
this.textBlock1.Text = isoFileReader.ReadLine();
}
}
this.btnWrite.IsEnabled = true;
this.btnRead.IsEnabled = false;
}
Please Help as soon you can.