Following code writes to file and reads from file in windows store app. This code can be a handler for a click event.
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFile file = await localFolder.CreateFileAsync("t.txt", CreationCollisionOption.ReplaceExisting);
await FileIO.WriteTextAsync(file, "Hello This is some text");
StorageFile f = null;
try
{
f = await localFolder.GetFileAsync("t.txt");
}
catch (Exception)
{
tbDummy.Text = "File DOes not exist";
}
if (f != null)
{
tbDummy.Text = await FileIO.ReadTextAsync(f);
}
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFile file = await localFolder.CreateFileAsync("t.txt", CreationCollisionOption.ReplaceExisting);
await FileIO.WriteTextAsync(file, "Hello This is some text");
StorageFile f = null;
try
{
f = await localFolder.GetFileAsync("t.txt");
}
catch (Exception)
{
tbDummy.Text = "File DOes not exist";
}
if (f != null)
{
tbDummy.Text = await FileIO.ReadTextAsync(f);
}
No comments:
Post a Comment