Is there a way with vb.net to browse for a file on the computer? I want to make a button the user clicks and it brings up Microsoft's normal browsing windows so they can browse and select a file off their C drive. Any ideas?
It usually is at the bottom of the toolbox.
Else right click on it, select "add/remove items", in the ".Net framework components" (selected by default) check the "OpenFileDialog":
NameSpace: System.Windows.Forms
EXCELLENT! You guys are great...I was looking for Windows Forms in the Add Items from the top tool bar instead of the toolbox....nice work, thanks!
A couple quick questions while I have your attentions. My next task is to take the take the file selected and rename it. If I use "ofdImport.FileName", it displays the entire path (which I'm displaying). But is there a good way to
1) just get the file name
2) rename the file with a string i collected elsewhere?
This works fine...but if the file is open it gives error message "An unhandled exception of type 'System.ArgumentException' occurred in microsoft.visualbasic.dll
Additional information: Procedure call or argument is not valid."
Is there a way, prior to renaming if we can close the file?
Try
' code to rename
Catch ex As Exception ' or System.ArgumentException
' MessageBox.Show("The file is already open. Close it!")
Finally
' code to execute whether there is exception or not.
End Try
Thanks for the tip.
My program can delete and rename but when the file is open it needs user input to actuly close by giving message. My requirements are if program finds the file open, the program closes it.
My question is I need to check with my program if file is opened (user might have opened the file by double clicking)program will close it then 2nd step will be rename or edit.
My point was that if the file was opened through your program you would be able to keep track of it - if external then another approach would be necessary.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.