There are some function that read all text from file without use FileStream class and more easy?
In microsoft doc found this code to read from file but I think is some complexed.
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
string filename = @"C:\Example\existingfile.txt";
char[] result;
StringBuilder builder = new StringBuilder();
using (StreamReader reader = File.OpenText(filename))
{
result = new char[reader.BaseStream.Length];
await reader.ReadAsync(result, 0, (int)reader.BaseStream.Length);
}
foreach (char c in result)
{
if (char.IsLetterOrDigit(c) || char.IsWhiteSpace(c))
{
builder.Append(c);
}
}
FileOutput.Text = builder.ToString();
}