Click here to Skip to main content
Click here to Skip to main content

FilesystemTree control in .NET

, 22 May 2003
Rate this:
Please Sign up or sign in to vote.
A FilesystemTree view control in VB.NET. Developed with VS.NET, using the system.management namespace.

The control

FilesystemTree is a control which will read the system resources and display a tree from which a user can navigate to a file or a folder...

Programmers can use this control as part of their applications to allow users to navigate to a folderList or fileSystemTree structure, and get back the file/folder path that the user has selected.

The code

The code is self-explanatory. Briefly, it has a TreeView control linked to an ImageList control. The ImageList control is for the TreeView to pick its icons from. To view the images in the ImageList control, open properties of the ImageList control and click on the ellipsis (...) next to the images property.

Using system.management namespace in .NET, the TreeView is filled with the resources/drives available on the system and as the user expands a node, sub-nodes are populated in a more user-friendly way. The textbox above the TreeView control is populated with the user's selection of a file/folder. The textbox is disabled... its only for viewing. The user's selection can also be accessed by using filesystemtree1.pathselected (if filesystemtree1 is an instance of the control on an application).

Using the code

Add the control to the project. If you are using VS.NET, right click on the toolbox in VS.NET -> Customize -> browse to the control's DLL and select. This will get the control on the toolbox. Drag and drop the control on to your application. If the control's instance on your application is called FilesystemTree1, use the code below, to get the user's selection.

//get the user's selection.

FileSystemTree1.pathselected

//

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Harish Palaniappan
Synechron Technologies, Pune
India India
Harish loves computers for their basic quality of running tasks given and doing things clockwork without day-dreaming like him.
 
Note: My employer does not subscribe to my thoughts posted in my articles.
Follow on   Twitter

Comments and Discussions

 
GeneralUpload MS Access Data on Network PinmemberSanjay C H19-Jun-06 3:08 
Generaltree duplicates file/directory names Pinmemberbc6018-Apr-06 8:05 
GeneralXP Icons Pinsussöalkfjöaldkfjaödlfkj???7-Feb-05 1:33 
GeneralVB .NET 1.1 - Out Of Memory Exception Pinmemberbranded218-Mar-04 4:35 

Hello All,
 
I'm a student using version 1.1 of VB .NET.
 
I was trying to make a freeware image viewer similar to older, leaner versions of ACDSee.
 
I have a drive/folder navigation listbox on the left side. Whenever the user navigates into a directory that contains images a list box on the right side displays a thumbnail of each image.
 
I started with 36 images and everything worked fairly well, although I cannot scroll through the thumbnails yet. I added another 36 images and I get an out of memory exception when I navigate into my image directory. With 72 thumbnails??? I have 1 gig of ram and this just doesn't seem right, even if the full image sizes are stored into memory. I know I've open 1500+ thumbnails in ACVDSee, so I'm far short in creating a similar program.
 
It also takes 3-4 seconds to make this simple check for 4 image extensions and to create and display a thumbnail for each found.. limited to 40 or so images before the dynamic memory is exhausted. I thought XP handled memory in a far more efficient way that utilizes the ram better.
 
Here is the code that throws the exception on approximately the 40th thumbnail created:
(from Mastering Visual Basic .NET; Evangelos Petroutsos)
 
===========================================================================
Private Sub ThumbNails()
 
Dim file As String
Dim FI As FileInfo
Dim PBox As PictureBox
Dim img As Image
Dim Left As Integer = 10
Dim Right As Integer = 40
Dim ctrl As Integer
Dim Top As Integer = 10
 
'Remove All PictureBox controls on the form:
For ctrl = (lst2.Controls.Count - 1) To 0 Step -1
lst2.Controls.Remove(lst2.Controls(ctrl))
Next
 
For Each file In Directory.GetFiles(mstrCurrentPath)
 
FI = New FileInfo(file)
 
If FI.Extension = ".gif" Or FI.Extension = ".jpg" Or FI.Extension = ".bmp" Or _
FI.Extension = ".png" Then
 
Try
img = Image.FromFile(FI.FullName)
FN = FI.FullName
PBox = New PictureBox
PBox.Image = img.GetThumbnailImage(100, 100, Nothing, Nothing)
If Left > 500 Then
Left = 10
Top = Top + 110
End If
 
PBox.Left = Left
PBox.Top = Top
PBox.Width = 100
PBox.Height = 100
 
PBox.Visible = True
PBox.Tag = FI.FullName
 
AddHandler PBox.Click, New System.EventHandler (AddressOf OpenImage)
Left += 110
lst2.Items.Add(PBox)
Catch
lst1.Items.Add(FI.FullName).ToString()
End Try
End If
 
FI = Nothing 'Trying to free dynamic mem:
PBox = Nothing

Next
End Sub
===========================================================================
 
I appreciate any comments or suggestions that you might have to help me along in this learning project.
 


GeneralRe: VB .NET 1.1 - Out Of Memory Exception PinmemberHarish Palaniappan24-Mar-04 5:05 
GeneralFileSystemTree Control Additions Pinmembercsnyder3-Nov-03 13:34 
GeneralDownload Error PinmemberAxelM22-May-03 22:41 
GeneralRe: Download Error PinmemberHarish Palaniappan23-May-03 0:14 
GeneralRe: Download Error PinmemberAxelM23-May-03 0:26 
GeneralRe: Download Error PinsussAnonymous28-May-03 6:46 
GeneralRe: Download Error PinsussAnonymous28-May-03 6:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 23 May 2003
Article Copyright 2003 by Harish Palaniappan
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid