How to resolve SystemUnauthorizedAccess Exception when accessing MyDocuments files in C#?

36 Views Asked by At

I've got the following exception:

SystemUnauthorizedAccess Exception: Access to the path <path> is denied.

with the following code:


                foreach (string doc in Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "*.*", SearchOption.AllDirectories).ToList())
                {
                    MessageBox.Show(doc);
                }

I need to get all file names in the MyDocuments hierarchy. Suggestions?

0

There are 0 best solutions below