943,844 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 4503
  • VB.NET RSS
Jan 26th, 2008
0

Store and retrieve numerous .wav and .bmp files

Expand Post »
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
slowburner is offline Offline
2 posts
since Jan 2008
Jan 26th, 2008
0

Re: Store and retrieve numerous .wav and .bmp files

Hi,

If the file is in a subfolder of your project then you can call it using its full path
VB.NET Syntax (Toggle Plain Text)
  1. Dim FilenameAndPath as String
  2.  
  3. FilenameAndPath = My.Application.Info.DirectoryPath & "\Images\Picture001.bmp"
  4. PictureBox.ImageLocation = FilenameAndPath
  5. 'or
  6. FilenameAndPath = My.Application.Info.DirectoryPath & "\Audio\Sound001.wav"
  7. My.Computer.Audio.Play(FilenameAndPath)
Reputation Points: 16
Solved Threads: 19
Junior Poster
ptaylor965 is offline Offline
169 posts
since Oct 2006
Jan 27th, 2008
0

Re: Store and retrieve numerous .wav and .bmp files

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
slowburner is offline Offline
2 posts
since Jan 2008
Jan 27th, 2008
0

Re: Store and retrieve numerous .wav and .bmp files

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
VB.NET Syntax (Toggle Plain Text)
  1. 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.
Reputation Points: 16
Solved Threads: 19
Junior Poster
ptaylor965 is offline Offline
169 posts
since Oct 2006
Jun 13th, 2009
0

Re: Store and retrieve numerous .wav and .bmp files

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Kruedog is offline Offline
1 posts
since Jun 2009
Jun 13th, 2009
0

Re: Store and retrieve numerous .wav and .bmp files

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

You will need to import System.Data

VB Syntax (Toggle Plain Text)
  1. Dim dt As New DataTable
  2.  
  3. 'Add the columns to build the file list
  4. dt.Columns.Add("FilePath", GetType(String))
  5. dt.Columns.Add("FileName", GetType(String))
  6.  
  7. 'For each file add them to the datatable
  8. For Each _File As String In IO.Directory.GetFiles(My.Application.Info.DirectoryPath & "\Resources\")
  9. 'New datarow to be built and added
  10. Dim dtRow As DataRow = dt.NewRow
  11.  
  12. 'Fill the columns with the file data
  13. dtRow("FilePath") = _File
  14. dtRow("FileName") = IO.Path.GetFileName(_File)
  15.  
  16. 'Add the row to the datatable
  17. dt.Rows.Add(dtRow)
  18. Next
  19.  
  20. Me.ListBox1.DataSource = dt 'Attach the datatable to a listbox
  21. Me.ListBox1.DisplayMember = "FileName" 'The column to show the user
  22. Me.ListBox1.ValueMember = "FilePath" 'The value column

And then to access the file information you can use
VB Syntax (Toggle Plain Text)
  1. 'Listbox1.Text shows the DisplayMember text and Listbox1.SelectedValue shows the ValueMember Value
  2. MessageBox.Show(Me.ListBox1.Text & vbCr & vbCr & Me.ListBox1.SelectedValue)
Last edited by ptaylor965; Jun 13th, 2009 at 2:17 pm. Reason: Syntax
Reputation Points: 16
Solved Threads: 19
Junior Poster
ptaylor965 is offline Offline
169 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: translate class diagram to sql script
Next Thread in VB.NET Forum Timeline: Windows Lock Computer





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC