Discussion on:

13
Comments

Join the conversation!

Follow via:
RSS
Email Alert
0 Votes
+ -
Contributr
Good article, I like to use it a little bit different since the ShowDialog() method returns the value.

I usually use:
If dlgOpenFile.ShowDialog = DialogResult.OK

Just because I tend to reuse dialog boxes, so handling the OK button could have disastrous results. happy

J.Ja
0 Votes
+ -
very good..
rapp000@... 24th Aug 2007
and also the OpenFileDialog has other userful properties such as the filter property wich allows to open a file in an specific format, i use it very often when i work with xml files.
0 Votes
+ -
Using the Filter property.
elitecobra@... Updated - 24th Aug 2007
Below is a small example of using the filter property.


OpenDialog1.Filter = "MP3 Files(*.mp3)|*.mp3|All Files (*.*)|*.*"

That will show the dialog with only MP3 files being visible or select the All Files combo item in the dialog to view them all. Either way its just a simple example. happy


Jason

http://www.vbcodesource.org
waha if I want just file name with no extension?
original path : c:\folder1\file.txt
i need
"file" only
0 Votes
+ -
Contributr
Look at the documentation for the System.File.IO namespace. It has everything you need for filename manipulation.

J.Ja
0 Votes
+ -
This link: http://vbcodesource.org/tips/?p=133 has a code snippet that will extract the filename without the path and without the extension.

Jason
with the filesystem.

Most use ones are File and Path in System.IO

Import / use it.

File. wait for good old intellisense to pop up and you get a whole stick of useful methods.
how to copy a file or text in vb.net
when i use your code for the openFileDialog the window comes up for the user to choose a file but after "OK" is clicked the windows close and the file does not open. i don't understand what i'm doing wrong. i'm very new to vb.net. please help!
The main purpose of the OpenFileDialog is to select a file and get the filename and path of the file the user selected. You can then do what it is you wanted to do with the file.

If you want to actually execute/open the file that the user selects, then try the code below...

----------------------

If OpenFileDialog.ShowDialog() = DialogResult.OK Then

Process.Start(OpenFileDialog.FileName)

End If

----------------------

You can also put the Process.Start(OpenFileDialog.FileName) code in the OpenFileDialog_FileOK event.

----------------------

Private Sub OpenFileDialog_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog.FileOk

Process.Start(OpenFileDialog.FileName)

End Sub

----------------------

That event is fired if the user selects a filename. IF the user cancels or whatnot, then the _FileOK event will not fire.



Anyways, hopefully you understand how the OpenFileDialog works and what its main purpose is.



Jason
so If I was to use a seprate button to access the file in the text box to stream write its contents to aother file.txt?
0 Votes
+ -
Because I'm new in programming, this simple open file dialog example has been very usefull to me.
Thanks a lot.
happy
Keyboard Shortcuts:
Prev
Next
Toggle
Join the conversation
Formatting +
BB Codes - Note: HTML is not supported in forums
  • [b] Bold [/b]
  • [i] Italic [/i]
  • [u] Underline [/u]
  • [s] Strikethrough [/s]
  • [q] "Quote" [/q]
  • [ol][*] 1. Ordered List [/ol]
  • [ul][*] · Unordered List [/ul]
  • [pre] Preformat [/pre]
  • [quote] "Blockquote" [/quote]

Join the TechRepublic Community and join the conversation! Signing-up is free and quick, Do it now, we want to hear your opinion.