Load a list of images from a directory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • luistkd
    New Member
    • Mar 2014
    • 1

    Load a list of images from a directory

    Hi, i would like to know the code so when i load a Form it shows me the list of images in a specific folder inside the app folder, but i dont know wich control to use, like imageslist or list view, so when i have in the form the display list of all the images in that folder i can select one and it shows the image in a picture box.

    Thank you so much for your help
  • TMafonoGames
    New Member
    • Mar 2014
    • 2

    #2
    Hello Luistkd

    You can use this to get your application location

    Code:
    Dim directory As String = My.Application.Info.DirectoryPath
    
    And Use 
    
    Dim di As New IO.DirectoryInfo(directory)
    Dim diar1 As IO.FileInfo() = di.GetFiles("*.jpg")
    Dim dra As IO.FileInfo
    
    For Each dra In diar1
    ListBox1.Items.Add(dra)
    Next
    
    To Get The Pictures In A ListBox 
    
    You Can Change This Line If The Pictures Are Not In A .jpg Extension To Any Other Extension
    
    Dim diar1 As IO.FileInfo() = di.GetFiles("*.jpg")
    
    So This Is The Final Code
    
    Dim directory As String = My.Application.Info.DirectoryPath
    Dim di As New IO.DirectoryInfo(directory)
    Dim diar1 As IO.FileInfo() = di.GetFiles("*.jpg")
    Dim dra As IO.FileInfo
    
    For Each dra In diar1
    ListBox1.Items.Add(dra)
    Next
    I Hope This Is What You Were Looking For
    Last edited by Rabbit; Mar 16 '14, 07:21 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Would help us to answer this question if you told us what type of project you are developing: WinForms, WPF, ASP.NET...???

      Here is an example of how to accomplish this in a WPF application.

      -Frinny
      Last edited by Frinavale; Mar 18 '14, 03:33 PM.

      Comment

      Working...