pr.StartInfo.FileName = Command.file1
pr.Start()
--
and I also tried:
-
ob1 = Command.file1
Dim pr As New Processpr.StartInfo.FileName = ob1
pr.Start()
--
but neither work, can someone give me a bit of help?
If IO.Directory.Exists(Command.file1) Then Process.Start(Command.file1) Else MessageBox.Show("The folder """ & Command.file1 & """ does not exist.") End If |
Dim sFile as String = Command.file1.Text.ToString() If IO.File.Exists(sFile) Then Dim pr As New Process pr.StartInfo.FileName = sFile pr.Start() End If |
If it is a TextBox then you need to use its Text property to get the string it contains. I suggest you explore the classes you are using a little bit.
uk_boy wrote:
It still does not work!! Command.file1 is a textbox in a form. When I run it I get an error saying that it is not a string. Can I change the textbox so it is regonized as a string?
I explored the classes but still I could not do it. For some reason the textbox is still not being converted into a string so when it gets to the:
"IO.File.Exists(sFile)" It takes it as false so no action happens. How can I fix this problem?
Can you paste some of your code? Just the relevant stuff, and i can help you out further.
Dustin.
Dim sFile as String = Command.file1.Text.ToString() If IO.File.Exists(sFile) To test my code I put "C:\" in the command.file1 which is a textbox, I also tried "C:\Program Files" both these files exist but both these things brought up the else statement.
Dim pr As New Process
pr.StartInfo.FileName = sFile
pr.Start()
Else
MessageBox.Show("The folder """ & Command.file1 & """ does not exist.")
End If
If you want to check if a directory exists, then use...
If IO.Directory.Exists() Then ....
IO.File.Exists() is used for checking if FILES exist! Not directories.
Dim sFile As String = Me.TextBox.ToString()
If IO.Directory.Exists(sFile) Then
Dim pr As New Processpr.StartInfo.FileName = sFile
pr.Start()
ElseMessageBox.Show(
"The folder """ & TextBox.Text & """ does not exist.") End IfBut it still seems not to be working it always jumps straight to the else part even with folders that I know exist.
Dim sFile As String = Me.TextBox.Text.ToString() Don't forget to add the .Text before the .ToString(). If that doesn't help, debug the code, and check the value of sFile at the If statement.