mjwsoft

Hello,

I am creating a Email station which will allow you to send emails to an email address along with attachments. However i have ran across a slight problem when looking for an attachment; I dont know how to open the file browser (the windows one) that will allow the user to look for files and just add them. I have this code but it only opens explorer which only opens my documents and obviously wont let me add files, just view them and use them:

Code Snippet

Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click

Shell("explorer.exe", AppWinStyle.NormalFocus, True, -1)

End Sub

Thanks,

Mitchell Wheeler



Re: Visual Basic Express Edition Opening a File Browser

Derek Smyth

Hi

Your looking for the OpenFileDialog. This class will let you create the file browser. Here is an example to demonstrate it's normal usage when only selecting one file, if the user selects more that one file (there is a property to enable to disable this behaviour) then your need to work with the OpenFileDialog.Filenames collection, it's a fairly straightforward class to use.

Code Snippet

Dim dlgOpen As New OpenFileDialog

dlgOpen.AddExtension = True

dlgOpen.Filter = "XML File (*.xml)|*.xml|Text File (*.txt)|*.txt|All File (*.*)|*.*"

'if the file open dialog result was OK then

If dlgOpen.ShowDialog = DialogResult.OK Then

Me.OpenFile(dlgOpen.FileName)

End If