Solved

Bind datalist with FileNames in a Directory

Posted on 2010-09-15
6
297 Views
Last Modified: 2013-11-26
Using vb.net, how would I get the file names from a directory and bind them to a datalist? Thanks
0
Comment
Question by:wilcor14
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33686292
What is a datalist, by the way?
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 33686308
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 33686317
DataList is a Databound control like Repeater/GridView controls.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33686371
You can use Directory.GetFiles
Imports System
Imports System.IO
.
.
.
. 
       Try
            
            Dim Flds As String() = Directory.GetFiles("c:\")
            Dim dir As String
            For Each dir In Flds
                Me.ListBox1.Items.Add(dir)
            Next
        Catch e As Exception
            MsgBox(e.ToString())
        End Try

Open in new window

0
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 500 total points
ID: 33686480
Or if you are using a datagridview...
 Dim NewCol As New DataGridViewTextBoxColumn
        NewCol.Name = "Files"
        Me.DataGridView1.Columns.Insert(0, NewCol)
        Try
            
            Dim Flds As String() = Directory.GetFiles("c:\")
            Dim dir As String
            For Each dir In Flds
                Me.DataGridView1.Rows.Add(dir)
            Next
        Catch e As Exception
            MsgBox(e.ToString())
        End Try

Open in new window

0
 

Author Closing Comment

by:wilcor14
ID: 33692233
Dim dir As DirectoryInfo = New DirectoryInfo(...)
Dim files() As FileInfo = dir.GetFiles
Dim list As ArrayList = New ArrayList
For Each oItem As FileInfo In files
list.Add(oItem)
Next
DataList1.DataSource = list
DataList1.DataBind()


 
 
<%#DataBinder.Eval(Container.DataItem, "Name")%>

 
 
 
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question