Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Bind datalist with FileNames in a Directory

Posted on 2010-09-15
6
Medium Priority
?
299 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
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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
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 1500 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

824 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