How do I read for example only the second line from text file containing of four lines located on the Windows Phone SD card or internal storage with UWP app coded in Visual C#?
Does internal storage mean the same as Computer\Windows phone\Phone in Explorer?
Since there are not a lot of details in your question I will assume the file you need is deployed with the application.
public async Task<string> ReadLine(int lineIndex)
{
var path = @"test.txt";
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
var file = await folder.GetFileAsync(path);
var lines = await Windows.Storage.FileIO.ReadLinesAsync(file);
if (lines.Count >= lineIndex + 1)
{
return line[lineIndex];
}
else
{
return null;
}
}
If the file is not deployed with the app, change the folder property to another one from here: Windows.Storage.ApplicationData.Current. (LocalFolder, TempFolder, RoamingFolder)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With