Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Bind datalist with FileNames in a Directory

Posted on 2010-09-15
6
Medium Priority
?
298 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

688 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