Question : Using System.IO.Directory.GetFil<wbr />es in VB.NET

I'm trying to convert an Excel VBA Macro to VB.NET as a windows forms.
The general idea is to copy Local copies of the files to 2 other locations (1 as Template, another as XLS)

i thought i would try something new/simpler instead of the FileSystemObject
Files = System.IO.Directory.GetFiles(FullPath, "*.xls", IO.SearchOption.AllDirectories)

But i get an error because there are hidden/protected system files somewhere in the subfolder.
A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll

Does anyone have any ideas?

I'm using VS 2010 Beta 2

Answer : Using System.IO.Directory.GetFil<wbr />es in VB.NET

Try this way instead using a recursive method
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
Public Class Form1

    Private fileList As New List(Of String)

    Sub getFiles(ByVal folderPath As String)
        Try
            For Each folder As String In System.IO.Directory.GetDirectories(folderPath)
                getFiles(folder)
            Next
            fileList.AddRange(System.IO.Directory.GetFiles(folderPath, "*.xls").ToList)
        Catch ex As Exception : End Try
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        For Each folder As String In IO.Directory.GetDirectories("Z:\Reports\Jet Reports\", "*.*")
            getFiles(folder)
        Next

        Stop 'check the fileList now

    End Sub

End Class
Random Solutions  
 
programming4us programming4us