Click here to Skip to main content
16,016,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,when i want to search in subfolders with this code,visual studio said to me "Access to the path 'D:\System Volume Information\' is denied."
How can i solve this problem?

     private string _strpath;
    _strpath = folderBrowserDialog.SelectedPath;
     string _strDirectoryName = txtName.Text ;

DirectoryInfo Ddirectory = new DirectoryInfo(_strpath);

listBox1.Items.Clear();

foreach (DirectoryInfo directory in Ddirectory.GetDirectories(_strDirectoryName,SearchOption.AllDirectories))
{
    listBox1.Items.Add(directory.Name);
}
Posted

 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 10-Jul-11 2:36am    
Raja, could you explain how all this is relevant to the OP's problem? I think it is not.
--SA
thatraja 10-Jul-11 2:46am    
Please leave the free attachments. Did you check the first link? It's an old question(with answers) in CP(similar question).
Sergey Alexandrovich Kryukov 13-Jul-11 0:38am    
Aha, now I got it -- thank you; voted 5.
--SA
Catch the exception and skip any directory for which you don't have access and then display a message to the user if appropriate.

Or filter out file/directory that are system and/or hidden.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 10-Jul-11 2:33am    
Correct, a 5.
--SA

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