I'm seeking for help with storing and retrieving/calling numerous sound and picture files. I've about 200 both .bmp and .wav files and it might get bigger. So I'm not sure if it's wise to embed that many files in the Resources, or should I add them to a special directory within my project and call them from there or else. VB 2005 does not recognize just a file's name even if it is located it the Resources so my question is how can I call file using just its name and not full path? And if I have to store my files in the special folder, I should propably search for that specific folder in the runtime and I need help with this one too. Thanks in advance.

Hi,

If the file is in a subfolder of your project then you can call it using its full path

Dim FilenameAndPath as String

FilenameAndPath  = My.Application.Info.DirectoryPath & "\Images\Picture001.bmp"
PictureBox.ImageLocation = FilenameAndPath
'or
FilenameAndPath  = My.Application.Info.DirectoryPath & "\Audio\Sound001.wav"
My.Computer.Audio.Play(FilenameAndPath)

Hello

and thanks for the reply! This property (My.Application.Info.DirectoryPath) returns
C:\VB\AppletNo1\AppletNo1\bin\Debug. I thought to place my "media" folder at the same place with Resources or so. In that case I've to go 2 levels up (which I've done using twice dir.Parent.FullName) to get to my folder. Since I'm a newby, my question is if this is the way usually used to store and handle pictures/sounds or there are other, may be more effective ways. Thanx

The best way i have found to deploy images, sound and other types of files is to place them in your "Resources" folder and then select the file in "solution Explorer" and change the property "Copy to Output Directory" to "Copy always"

This will copy your images and other files to your application folder on deploy
i.e. "C:\VB\AppletNo1\AppletNo1\bin\Debug\Resources\media\"

and your will ba able to use

My.Application.Info.DirectoryPath & "\Resources\media\"

This is because when you deploy the application the current folder "C:\VB\AppletNo1\AppletNo1\bin\Debug\" will be replaced by your application location which will not contain your Resources folder unless files are set to copy.

Hello

I was trying to do a similar thing putting files in my resource folder and accessing them according to the user choice on a DropDownList. But now I'm wondering how could call the file from the folder according to the user selection and not have to code each file one by one. Could i declare a string variable with the selected.text from the dropdownlist for value and continue with the file path such as...
[
Dim curImage As String
Dim cur As String

cur = ImageBox.Text
curImage = My.Application.Info.DirectoryPath & "\Resources\Images\" &"cur"&".jpg"

PictureBox1.Image = curImage

To do this I would (and have) used a datatable

You will need to import System.Data

Dim dt As New DataTable

'Add the columns to build the file list
dt.Columns.Add("FilePath", GetType(String))
dt.Columns.Add("FileName", GetType(String))

'For each file add them to the datatable
For Each _File As String In IO.Directory.GetFiles(My.Application.Info.DirectoryPath & "\Resources\")
   'New datarow to be built and added
   Dim dtRow As DataRow = dt.NewRow

   'Fill the columns with the file data
   dtRow("FilePath") = _File
   dtRow("FileName") = IO.Path.GetFileName(_File)

   'Add the row to the datatable
   dt.Rows.Add(dtRow)
Next

Me.ListBox1.DataSource = dt 'Attach the datatable to a listbox
Me.ListBox1.DisplayMember = "FileName" 'The column to show the user
Me.ListBox1.ValueMember = "FilePath" 'The value column

And then to access the file information you can use

'Listbox1.Text shows the DisplayMember text and Listbox1.SelectedValue shows the ValueMember Value
MessageBox.Show(Me.ListBox1.Text & vbCr & vbCr & Me.ListBox1.SelectedValue)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.