Solved

Bind datalist with FileNames in a Directory

Posted on 2010-09-15
6
287 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now