Listbox

Fill with Folder Names

Page 1 of 1

4 Replies - 8064 Views - Last Post: 08 September 2006 - 04:47 AM Rate Topic: -----

#1 Graham  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 49
  • Joined: 07-June 06

Listbox

Posted 26 August 2006 - 01:59 AM

How do I fill a listbox with the names of the folders in a folder i.e

C:\Folder_1\Folder_First
C:\Folder_1\Folder_Second
C:\Folder_1\Folder_Third

Listbox shows the folder Names

Folder_First
Folder_Second
Folder_Third
Is This A Good Question/Topic? 0
  • +

Replies To: Listbox

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Listbox

Posted 26 August 2006 - 11:16 AM

You will want to use the DirectoryInfo.GetDirectories methods.

Here is the MSDN showing how.

This post has been edited by jayman9: 26 August 2006 - 12:55 PM

Was This Post Helpful? 0
  • +
  • -

#3 Fygar  Icon User is offline

  • I liek milk!!1
  • member icon

Reputation: 6
  • View blog
  • Posts: 4,361
  • Joined: 28-March 02

Re: Listbox

Posted 28 August 2006 - 08:23 AM

Tested and approved:

		using System.IO;

		DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath(""));

		dlFiles.DataSource = dirInfo.GetFileSystemInfos();
		dlFiles.DataBind();



This returns directories and files.
Was This Post Helpful? 0
  • +
  • -

#4 ynrrakesh@yahoo.com  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 06-September 06

Re: Listbox

Posted 08 September 2006 - 12:09 AM

Imports System.IO

Dim info As DirectoryInfo = New DirectoryInfo("C:\Folder_1")
ListBox1.DataSource =info.GetFileSystemInfos()
ListBox1.DataBind()
Was This Post Helpful? 0
  • +
  • -

#5 Graham  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 49
  • Joined: 07-June 06

Re: Listbox

Posted 08 September 2006 - 04:47 AM

Here's what worked for me.
Private Sub frmOptions_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		Dim theFolders() As String

		theFolders = Directory.GetDirectories("C:\MainFolder\")

		For Each currentFolder As String In theFolders
			Me.lstTheme.Items.Add(currentFolder.Substring(currentFolder.LastIndexOf("\") + 1))
		 Next

	End Sub


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1