Hi All,
How to open and read .txt file in UWP?
I am getting "Access denied" error by using below code.
- using (OpenFileDialog openFileDialog = new OpenFileDialog())
- {
- openFileDialog.InitialDirectory = "c:\\";
- openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
- openFileDialog.FilterIndex = 2;
- openFileDialog.RestoreDirectory = true;
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
-
- filePath = openFileDialog.FileName;
-
- var fileStream = openFileDialog.OpenFile();
- using (StreamReader reader = new StreamReader(fileStream))
- {
- fileContent = reader.ReadToEnd();
- }
- }
- }
- MessageBox.Show(fileContent, "File Content at path: " + filePath, MessageBoxButtons.OK);
Please provide the solution.