Reputation: 361
I am developing windows store app. I have this text file named: text.txt
account1 string1
account2 string2
account3 string3
And this c# code:
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
var path = "text.txt";
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
try
{
var file = await folder.GetFileAsync(path);
}
catch (FileNotFoundException)
{
test.Text = "error";
}
}
Code can find text file without a problem. But i cannot read it. I want to read account names(account1, account2, account3) from text file, and add it into an arraylist named "x" And add strings(string1, string2, string3) to arraylist named "y".
I would appreciate your helps. Regards...
Upvotes: 2
Views: 3652
Reputation: 18823
You can read the file into a string collection using ReadLinesAsync:
try
{
var file = await folder.GetFileAsync(path);
var lines = await FileIO.ReadLinesAsync(file);
foreach (string line in lines)
{
// "line" variable should contain "account(x) string(x)"
// You can then parse it here..
}
}
...
Upvotes: 3