0

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?

gpicchiarelli
  • 454
  • 6
  • 16
  • 2
    What is the value for the Path in the error message? Probably there are one or more folders or files that don't allow access to the current user running the code above. Did you try to run this code as administrator? – Steve May 28 '23 at 18:00
  • C:\Users\user1\Documents\Immagini, in a mixed language fashion. I ran as administrator and I got same error. – gpicchiarelli May 28 '23 at 18:07
  • 2
    [Similar question](https://stackoverflow.com/questions/4986293/access-to-the-path-is-denied-when-using-directory-getfiles) – Ibram Reda May 28 '23 at 18:09
  • 1
    https://stackoverflow.com/questions/34947623/liststring-of-paths-to-hierarchical-structure check this out – sep7696 May 29 '23 at 12:49

0 Answers0