How to read data from a text file in Isolated Storage in Windows Phone ?

In my previous blog post , i explained How to write data to a file in Isolated Storage in Windows Phone ?

In this blog post , will show you How to read data from a text file in Isolated Storage in Windows Phone that was written to the Isolated Storage .

How to read data from a text file in Isolated Storage in Windows Phone ?

1. Add the namespace IsolatedStorage

using System.IO.IsolatedStorage;

2. Retreive the userscope isolated storage that belongs to the App to the IsolatedStorageFile using the IsolatedStorageFile.GetUserStoreForApplication

IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();

3. Verify if the file exists in the Isolated Storage with the FileExists method of the IsolatedStorageFile class .

iso.FileExists("Employees.txt")

4. Open the File with the OpenFile function of the IsolatedStorageFile  and assign it to the IsolatedStorageFileStream .

IsolatedStorageFileStream stream = iso.OpenFile("Employees.txt", System.IO.FileMode.Open);

5. Create an instance of the StreamReader with the IsolatedStorageFileStream that was created above as the parameter .

StreamReader streamReader = new StreamReader(stream);

6. Write the Data from the textbox to the StreamWriter and close the StreamWriter

textBox1.Text = streamReader.ReadToEnd();
streamReader.Close();
private void button2_Click(object sender, RoutedEventArgs e)
{
   IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();
   if (iso.FileExists("Employees.txt"))
   {
     IsolatedStorageFileStream stream = iso.OpenFile("Employees.txt", System.IO.FileMode.Open);
     StreamReader streamReader = new StreamReader(stream);
     textBox1.Text = streamReader.ReadToEnd();
streamReader.Close();
   }
}


via WindowsPhoneRocks.com

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Reply


x

Interesting BlogPosts to read

Download - Pokemon Go for for Windows 10 (Third Party app)
Pokemon Go is one of the popular AR games for android and iOS devices and now , the game is made ava...
Open Wordpad from command line in Windows
You can use the command "Write" from command line in Windows to open the WordPad application.D:\>...
Popular cross-platform (android and iOS) to-do list app
In this blog post, we will cover some of the popular to-do list app that is available on different p...