I am just writing a simple file browser. It works without problems when i point to a specific directory but throws "UnauthorizedAccessException access to the path .... is denied" when i point to drive "C:\\" or "D:\\" appreciate any help.

If Not txtToSearch.Text = Nothing Then
            ListBox1.Items.Clear()
            FC = 0
            For Each foundfile As String In My.Computer.FileSystem.GetFiles("D:\\", FileIO.SearchOption.SearchAllSubDirectories, Nothing)
                Dim title As String = My.Computer.FileSystem.GetFileInfo(foundfile).Name
                If title.Contains(txtToSearch.Text) Then
                    ListBox1.Items.Add(title)
                    FC += 1
                End If
            Next

Just curious, do you use "D:\\" or D:\" to access to the root directory of drive?

yes i tried both of them and got the exception in that case.

Ok.
The error generated by GetFiles, comes from a folder that you do not have enough privileges to read all the contents.

In the exception, you have the offending folder (ie: on Vista, "Access to the path 'C:\Documents and Settings' is denied".)

As this can happen in many others folders, I would suggest not to get all the file names in the drive with only one sentence.

Moreover, if you count the files and folder in the drive, you can get a lot of thousands, so this can be unmanageable in a listbox.

Hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.