Solved

Bind datalist with FileNames in a Directory

Posted on 2010-09-15
6
295 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Help 27 57
Dot Net 4.6.1 installation fails on W2012 R2 server 14 39
VB.NET String Settings and Temp Folder Question 3 55
Code works but breaks when I add one section 4 20
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

830 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