List Files in a Directory in VB.NET





3
Date Submitted Sat. Oct. 15th, 2005 5:32 PM
Revision 1 of 1
Helper ses5909
Tags Directory | Files | List | VB.NET
Comments 1 comments
List Files in a Directory in VB.NET
'you can get an array of files (their path) by using:
fileArray = Directory.GetFiles(yourPath)

'
this example shows how to loop through a directory and show all of the GIF images in  it.

Dim pics as ArrayList = new ArrayList() ' an ArrayList to Bind to a control
Dim myFile as String, code as String '
file and html code strings
Const YOUR_DIRECTORY as String = "/images/" ' constant for your image directory


For Each myFile in Directory.GetFiles(Server.MapPath(YOUR_DIRECTORY), "*.gif")
    image =  YOUR_DIRECTORY & Path.GetFileName(myFile)
    code = "<img src=""" & image & """><br>"
    pics.Add(code) '
add the image to your ArrayList
Next

'Bind the pics to a DataList
dlImages.DataSource = pics
dlImages.DataBind

Sara Smith

www.ilovecode.com
Sara

ilovecode

Comments

Comments better performance
Tue. Sep. 5th, 2006 7:19 PM    Helper jbplou

Voting