open file & mycomputer
I hope someone can help me, i have made a contextmenu and i want it to goto the mycomputer folder and then when a file is selected that it starts the file now i already have the openfiledialog and such and i use the code listed below. But it will not start in the mycomputer directory and it will not open the file if i change the > to < then it won't cancel if i choose not to open a file can anyone help me get the code fixed ?
| | PrivateSub ComputerToolStripMenuItem_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles ComputerToolStripMenuItem.Click Dim mycomputerAsString mycomputer = System.Environment.GetFolderPath( _ Environment.SpecialFolder.MyComputer) Dim pAsNew System.Diagnostics.Process() Me.OpenFileDialog1.Title = "My Computer - Open File" Me.OpenFileDialog1.ShowDialog() Me.OpenFileDialog1.InitialDirectory = mycomputer IfMe.OpenFileDialog1.FileName >NothingThen p.StartInfo.FileName =Me.OpenFileDialog1.FileName Else ExitSub p.Start() EndIf EndSub
|
also i have tried the following code but then when i decide not to open a file it hangs what am i missing that will make it so when i decide not to open anything that it will still continue to run the application and not hang and how do i make it start in the mycomputer folder ?
| | Dim iAsInteger OpenFileDialog1.Filter = "All Files (*.*)|*.*" OpenFileDialog1.RestoreDirectory =True OpenFileDialog1.ShowDialog()If OpenFileDialog1.FileName = ""Then EndIf Process.Start(OpenFileDialog1.FileName) ExitSub
|
I hope someone can help me correct the code so it works.
[3151 byte] By [
CyberOps] at [2007-12-16]
You want to check the openFileDialog's DialogResult to make sure the user clicked Open before passing the .FileName to Process.Start().
Dim mycomputer As String
mycomputer = System.Environment.GetFolderPath( _
Environment.SpecialFolder.MyComputer)
Dim p As New System.Diagnostics.Process()
Dim dr As New DialogResult()
Me.OpenFileDialog1.Title = "My Computer - Open File"
Me.OpenFileDialog1.InitialDirectory = mycomputer
dr = Me.OpenFileDialog1.ShowDialog(Me)
If dr = System.Windows.Forms.DialogResult.OK Then
p.StartInfo.FileName = Me.OpenFileDialog1.FileName
p.Start()
End If