473,411 Members | 2,285 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

vb.net example please

Hi

Could someone please provide an example of opening a file browser, selecting
several files and adding them to a lst box?

Thanks

Regards
Nov 20 '05 #1
3 5357
Cor
John,
You don't need it when you have VB.net 2003 it is in the toolbox.
Just drag to your form
Cor
Nov 20 '05 #2
Hi John,

You're in luck! I did this answering another query so here it is on a
plate!!

It starts Explorer as the file browser with a given file path. Then the
ListBox waits for files to be dropped onto it. The routine that actually puts
the files into the ListBox is separate in case you want to allow other
Controls to accept the files but divert them to the ListBox.

Regards,
Fergus

<code>
'================================================= ==================
'If the FilePath is bad, Explorer will show a dialogue box.
'The Exception Catch below is for other errors.
Public Sub CallExplorer (sFilePath As String)
Try
Process.Start ("Explorer.exe", "/e, " & sFilePath)
Catch e As Exception
MsgBox ("Couldn't start Explorer in " & sFilePath & vbCrLf &
e.Message)
'or
Throw New Exception ("Couldn't start Explorer in " & sFilePath, e)
End Try
End Sub

'================================================= ==================
Private Sub ListBox1_DragEnter(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs) _
Handles ListBox1.DragEnter

'Only allow drag-n-drop if it's from Explorer.
If e.Data.GetDataPresent (DataFormats.FileDrop) Then
e.Effect = DragDropEffects.All
Else
e.Effect = DragDropEffects.None
End If
End Sub

'================================================= ==================
Private Sub ListBox1_DragDrop(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs) _
Handles ListBox1.DragDrop

'Only allow graphics files to be accepted.
'Note the '.' at each end.
Dim sAllowedExtensions As String = ".jpg.bmp.gif."

'Put the list of files that have been dropped into a ListBox.
Dim asFiles() As String
asFiles = CType (e.Data.GetData ("FileDrop"), String())
DisplayFiles (asFiles, ListBox1, sAllowedExtensions)

End Sub

'================================================= ==================
'Files must match one of the given extensions.
'Files without an extension will never be matched.
Sub DisplayFiles (asFiles() As String, oListBox As ListBox, _
sAllowedExtensions As String)

oListBox.Items.Clear

Dim sFileName As String
For Each sFileName In asFiles
'Extract the extension.
Dim PosOfExt As Integer = ("." & sFileName).LastIndexOf (".")
Dim sExt As String = sFileName.Substring (PosOfExt)

'Only allow files with the correct extension.
If sAllowedExtensions.IndexOf ("." & sExt & ".") >= 0 Then
oListBox.Items.Add (sFileName)
End If
Next
End Sub
</code>
Nov 20 '05 #3
Many thanks. Its very useful.

Regards
"Fergus Cooney" <fi******@tesco.net> wrote in message
news:uJ**************@TK2MSFTNGP09.phx.gbl...
Hi John,

You're in luck! I did this answering another query so here it is on a
plate!!

It starts Explorer as the file browser with a given file path. Then the ListBox waits for files to be dropped onto it. The routine that actually puts the files into the ListBox is separate in case you want to allow other
Controls to accept the files but divert them to the ListBox.

Regards,
Fergus

<code>
'================================================= ==================
'If the FilePath is bad, Explorer will show a dialogue box.
'The Exception Catch below is for other errors.
Public Sub CallExplorer (sFilePath As String)
Try
Process.Start ("Explorer.exe", "/e, " & sFilePath)
Catch e As Exception
MsgBox ("Couldn't start Explorer in " & sFilePath & vbCrLf &
e.Message)
'or
Throw New Exception ("Couldn't start Explorer in " & sFilePath, e) End Try
End Sub

'================================================= ==================
Private Sub ListBox1_DragEnter(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs) _
Handles ListBox1.DragEnter

'Only allow drag-n-drop if it's from Explorer.
If e.Data.GetDataPresent (DataFormats.FileDrop) Then
e.Effect = DragDropEffects.All
Else
e.Effect = DragDropEffects.None
End If
End Sub

'================================================= ==================
Private Sub ListBox1_DragDrop(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs) _
Handles ListBox1.DragDrop

'Only allow graphics files to be accepted.
'Note the '.' at each end.
Dim sAllowedExtensions As String = ".jpg.bmp.gif."

'Put the list of files that have been dropped into a ListBox.
Dim asFiles() As String
asFiles = CType (e.Data.GetData ("FileDrop"), String())
DisplayFiles (asFiles, ListBox1, sAllowedExtensions)

End Sub

'================================================= ==================
'Files must match one of the given extensions.
'Files without an extension will never be matched.
Sub DisplayFiles (asFiles() As String, oListBox As ListBox, _
sAllowedExtensions As String)

oListBox.Items.Clear

Dim sFileName As String
For Each sFileName In asFiles
'Extract the extension.
Dim PosOfExt As Integer = ("." & sFileName).LastIndexOf (".")
Dim sExt As String = sFileName.Substring (PosOfExt)

'Only allow files with the correct extension.
If sAllowedExtensions.IndexOf ("." & sExt & ".") >= 0 Then
oListBox.Items.Add (sFileName)
End If
Next
End Sub
</code>

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Alberto | last post by:
An OUTSTANDING example of a rebuttal. Worth a glance. Rather long, OBVIOUSLY feel fee to dismiss it entirely if not interested. But this habit of the rebuttals must go to a stop (forgive odd...
10
by: Xah Lee | last post by:
today i need to use Python to decompress gzip files. since i'm familiar with Python doc and have 10 years of computing experience with 4 years in unix admin and perl, i have quickly located the...
1
by: pokémon | last post by:
Can someone please post a working example of how to use the WaitAny() method. Thanks.
11
by: ajikoe | last post by:
Hello, I used Visual C# Standard Edition. I want to comment my program using xml commentary method, I don't know why if I use value and example tag, it is not working / showed in the html...
6
by: Jim Hubbard | last post by:
Anybody seen an example of a snap-in GUI done in VB.Net?
5
by: aualias | last post by:
I am trying to run the Secure Conversation example in WSE 2.0. On the call to client.IssueSecurityContextTokenAuthenticated(token, issuerToken); I get the following exception: ...
67
by: gator | last post by:
I am quite new to XML and posted a request for example code yesterday. Unfortunately, I did not do a very good job in explaining what I was looking for. Here is an example of a small piece of the...
19
by: Richard | last post by:
Hi All, I copied a script example from http://www.irt.org/script/640.htm into a local .html file. I opened that file first in HTML-kit, which hung (in an infinite loop, I think) when I...
7
by: Mark B | last post by:
Can someone write some VB.Net example code for me that does this: 1) Creates a gridview control with the results of a SQL stored procedure that has 1 parameter (text) 2) Adds an extra column...
6
by: Peter | last post by:
I have a APS.NET 3.5 webpage which calls a web service. What I need is to update this page automatically when a value changes in the webservice, does anyone have an example? Thank You ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.