VB.NET - LINQ query to get list of files and bind to DataGridView



Query to get list of files from current directory

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                'get files from current directory 
        Dim Files = From file In My.Computer.FileSystem.GetFiles(CurDir)
                    Order By file
                    Select file
'returns IEnumerable of FileInfo object that contains file information
        Dim Filesinfo = From File In Files Select My.Computer.FileSystem.GetFileInfo(File)
        'Bind to grid 
        'ToList() is to get FileInfo
        DataGridView1.DataSource = Filesinfo.ToList()       
    End Sub

Share |

 Cant find the page you are looking for?
 Help us to improve by adding the content that you are looking for.
 Leave a feedback
 We look forward to hear your comments and feedback.