|
-
Aug 19th, 2012, 05:40 PM
#1
Thread Starter
New Member
How to read the value from textbox and use as file path?
Hi all,
I am a beginner in Visual Basic. I use Visual Studio 2008.
I don't know how to solve this problem.
I would like to run a file name xyz.exe from "c:\test\number\" directory.
I have a browse button (Button3) to set the working directory ( c:\test\number\), and the path is shown in my TextBox1.
I would like to get the Run button (Button1) to run the xyz.exe file from the previously selected directory.
The code for Button3
Code:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim BrowseFolder As New FolderBrowserDialog
BrowseFolder.ShowDialog()
TextBox1.Text = BrowseFolder.SelectedPath
MsgBox(BrowseFolder.SelectedPath)
End Sub
The code for Button1
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
System.Diagnostics.Process.Start( "\xyz.exe")
End Sub
Can you please help me to solve this problem?
Thank you
Poli
-
Aug 19th, 2012, 05:46 PM
#2
Re: How to read the value from textbox and use as file path?
Slightly odd way of going about it but ...
Process.Start(TextBox1.Text & "\xyz.exe")
-
Aug 19th, 2012, 06:23 PM
#3
Thread Starter
New Member
Re: How to read the value from textbox and use as file path?
Great,
Thank you.
Only one more question:
How can I make that if the selected folder doesn't contain the file a msgbox says there is no file in selected directory and after hitting OK, it goes back to my panel and not freeze?
Thank you again for your help
-
Aug 19th, 2012, 07:43 PM
#4
Re: How to read the value from textbox and use as file path?
Take a look at the various classes in System.IO. There should be a path object, and a file object (though one of those may not actually be an object). You can use the tools in there to figure out various things, such as whether or not the user entered a valid path, whether or not the file exists, and so forth. You want to check out that entry before calling Start.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|