This question already has an answer here:
- Read file from subfolder of application installation folder 4 answers
I am trying to read the content of a text file but I get the 'Access to the path is denied' exception of type 'System.UnauthorizedAccessException'. I've tried the following:
- Ran Vs in Administrator mode
- Checked if the file is read only
- Checked if the file is hidden
- Checked if the file has full control on all users
My code:
private async void MyButton_Click(object sender, RoutedEventArgs e)
{
string path = @"fullpath\TextFile.txt";
await Task.Run(() =>
{
string text = File.ReadAllText(path);
});
}