Click here to Skip to main content
15,890,399 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i use this code to select a path and get all subdirectories of it



if (FBD_devis.ShowDialog() == DialogResult.OK)
             {
                 try
                 {

                DirectoryInfo diri_info = new DirectoryInfo(FBD_devis.SelectedPath);

                     listBox2.Items.AddRange(diri_info.GetDirectories("*",    SearchOption.AllDirectories));

                 }
                 catch (UnauthorizedAccessException u)
                 {
                     MessageBox.Show("le problème c'est a cause ce Dossiers: " + u.Message + "\n" + u.Source);

                 }
             }
         }


but when i select the path
[^]

it generate this problem
[^]

how can I fix this problem please ?

What I have tried:

I tried to look for how to ignore this type of directories but I could not solve the problem.
Posted
Updated 6-Jul-17 17:06pm

1 solution

So your problem is your application doesn't have proper permissions to access c:\users\inconnu\documents\ma music. Your first screenshot only shows the shortcut to your documents folder (which doesn't help much).

Your solution here is to either run your code with administrator privileges, figure out what user is going to run your app and assign proper permissions to the directory, or choose a different folder that doesn't require elevated permissions to access that directory.

You don't specify if this is a web app or if it as winforms/desktop app, only see "forms" as a tag. If it is a webforms app i would highly recommend you don't allow your web application access to your local directories in this manner, it becomes a security issue among other things.

Some links for running as admin/forcing run as admin

c# - How do I force my .NET application to run as administrator? - Stack Overflow[^]

Google[^]
 
Share this answer
 
Comments
Moumni Mohamed 7-Jul-17 3:27am    
it as winforms/desktop app
to help searching for specific file (invoice and quotation)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900