+ 1

Access denied from Directory.Getfiles(path, name, Searchoption.Alldirectory)

How to solve this problem in C#? I got somethings like "Unauthorized Access denied" when i try to use Directory.getfiles(@"d:\", "*", searchoption.alldirectory);

4th Aug 2017, 7:11 PM
Puntawat Poonitipunt
Puntawat Poonitipunt - avatar
4 odpowiedzi
+ 17
https://stackoverflow.com/questions/8821410/why-is-access-to-the-path-denied Run Code as Admin... (find option in IDE). Grant superuser/elevated privilledges to your program. Fix file/folder readonly permissions.
4th Aug 2017, 7:21 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 2
Thank you, ValentinHacker
4th Aug 2017, 7:22 PM
Puntawat Poonitipunt
Puntawat Poonitipunt - avatar
+ 1
Try to make it smaller. Try to create a file in "d:\", do you have rights there ? if you use : Directory.getfiles(@"d:\"); does it work ? If the small thing is working, you can go bigger. SearchAllDirectory is a pretty huge area, you probably do not have access everywhere. https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/file-system/how-to-iterate-through-a-directory-tree
4th Aug 2017, 9:11 PM
sneeze
sneeze - avatar
0
Thank you, @sneeze. :) I just follow your suggestions. and found that it is a problem of permission like @ValentinHacker's mention above. because when i skip secured folder, it work well.
5th Aug 2017, 4:22 AM
Puntawat Poonitipunt
Puntawat Poonitipunt - avatar