| | |
Store and retrieve numerous .wav and .bmp files
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2008
Posts: 2
Reputation:
Solved Threads: 0
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
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)
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)
•
•
Join Date: Jan 2008
Posts: 2
Reputation:
Solved Threads: 0
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
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 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.
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)
My.Application.Info.DirectoryPath & "\Resources\media\"
•
•
Join Date: Jun 2009
Posts: 1
Reputation:
Solved Threads: 0
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
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
And then to access the file information you can use
You will need to import System.Data
VB Syntax (Toggle Plain Text)
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
VB Syntax (Toggle Plain Text)
'Listbox1.Text shows the DisplayMember text and Listbox1.SelectedValue shows the ValueMember Value MessageBox.Show(Me.ListBox1.Text & vbCr & vbCr & Me.ListBox1.SelectedValue)
Last edited by ptaylor965; Jun 13th, 2009 at 2:17 pm. Reason: Syntax
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: translate class diagram to sql script
- Next Thread: Windows Lock Computer
| Thread Tools | Search this Thread |
.net .net2008 30minutes 2005 2008 access account arithmetic array basic bing button buttons center check code combobox component connectionstring crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dropdownlist excel fade file-dialog filter folder ftp generatetags google gridview hardcopy images input insert intel internet mobile monitor ms net networking objects output panel passingparameters peertopeervideostreaming picturebox picturebox1 port position print printing problem problemwithinstallation project save searchbox searchvb.net select serial shutdown soap survey table tcp temperature text textbox timer timespan toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year





