Muhammad Nasir Khan
Muhammad Nasir Khan

Reputation: 59

Writing files in windows phone 8

I want to read and write data from a Text file in windows phone 8 application. I tried this code

IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
StreamWriter wr = new StreamWriter(new IsolatedStorageFileStream("File.txt", FileMode.OpenOrCreate, isf));
wr.WriteLineAsync("Hello");
wr.Close();

But it does nothing. Please help me out of this problem. Thanks.

Upvotes: 0

Views: 101

Answers (1)

Ajay
Ajay

Reputation: 6590

Write data to file:

IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();

//create new file
using (StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream("myFile.txt", FileMode.Create, FileAccess.Write, myIsolatedStorage)))
{
   string someTextData = "This is some text data to be saved in a new text file in the IsolatedStorage!";
   writeFile.WriteLine(someTextData);
   writeFile.Close();
}

Read data from file:

IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("myFile.txt", FileMode.Open, FileAccess.Read);
using (StreamReader reader = new StreamReader(fileStream))
{    
     //Visualize the text data in a TextBlock text
     this.text.Text = reader.ReadLine();
}

Go through this links: http://www.geekchamp.com/tips/all-about-wp7-isolated-storage-read-and-save-text-files

https://www.google.co.in/#q=wp8+isolated+storage+geek

Upvotes: 1

Related Questions