Click here to Skip to main content
16,010,114 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have to use openfiledialog container.
& folder of selected directory should be display in datagrid

i aiso try to use files = Directory.GetFiles(stFileName) but it not work properly.

please help
Posted

I hope it works for you.
Dim strFilename() As String
        strFilename = System.IO.Directory.GetFiles("Path")
        Dim dt As New DataTable
        dt.Columns.Add("FileName")
        dt.Columns.Add("FilePath")
        For i As Integer = 0 To strFilename.Length - 1
            Dim dr As DataRow
            dr = dt.NewRow
            dr.Item(0) = System.IO.Path.GetFileName(dt.Rows(i).Item(0))
            dr.Item(1) = dt.Rows(i).Item(0).ToString
            dt.Rows.Add(dr)
        Next
        DataGridView1.DataSource = dt
 
Share this answer
 
VB
Dim thing As String

       Dim folder As String

       Dim Files2Open As Array

       Dim row As Integer
       row = 0

       If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
           folder = OpenFileDialog1.FileName.Substring(0, _
           OpenFileDialog1.FileName.LastIndexOf("\") + 1)
           Files2Open = Directory.GetFiles(folder)
           'DataGridView1.Columns.Add("Column1", "FileName")

           For Each thing In Files2Open
               DataGridView1.Rows.Add()
               DataGridView1.Item(0, row).Value = thing
               row = row + 1

           Next

       End If
 
Share this answer
 

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