如何使用process.start打开文件? [英] How do I open a file using process.start?
问题描述
我有一些代码可以使用记事本或写字板打开文件。我试图能够使用用户选择的文本编辑器打开相同的文件。我尝试使用Microsoft Word作为测试但无法使其工作。这是我的代码(哦:变量OtherPuzzleEditorPath在模块中定义为Public):
I have some code that can open a file with either Notepad or Wordpad. I am attempting to be able to open the same file with a text editor of the users choice. I tried Microsoft Word as a test but cannot get it to work. Here is my code (oh: the variable "OtherPuzzleEditorPath" is defined as Public in a module):
Private Sub viewBtn_Click(sender As Object, e As EventArgs) Handles viewBtn.Click
Dim MySelectedPath As String = Nothing
Dim MySelectedExt As String = Nothing
Dim EditorPath As String = Nothing
Select Case True
Case RadioButton1.Checked
MySelectedPath = PuzzlePath
MySelectedExt = ".wsp"
Case RadioButton2.Checked
MySelectedPath = SolutionsPath
MySelectedExt = ".wss"
End Select
EditorPath = MySelectedPath & ListBox3.SelectedItem.ToString & MySelectedExt
Select Case True
Case OpenWithNotepad
Process.Start("Notepad.exe", EditorPath)
Case OpenWithWordpad
Process.Start("Wordpad.exe", Chr(34) & EditorPath & Chr(34)) 'DONT CHANGE THIS LINE!
Case OpenWithOther
Process.Start(OtherPuzzleEditorPath & Space(1) & EditorPath)
End Select
ListBox3.ClearSelected()
deleteBtn.Enabled = False
viewBtn.Enabled = False
End Sub<pre lang="vb">
我尝试过:
定义两个字符串的不同变体:ie(Chr(34) )& [路径]& Chr(34)),更改为可执行文件在FIRST中的目录,然后使用文件路径运行它。
What I have tried:
Different variations of defining both strings: ie(Chr(34) & [path] & Chr(34)), changing to the directory the executable is in FIRST, then running it with the path of the file.
推荐答案
您更改了传递参数的方式当你添加OtherPuzzleEditor时。你没有提供空格然后提供参数。
您应该将可执行文件传递给启动,并将其参数作为Start调用的单独参数传递。更改代码:
You changed the way you passed parameters when you added your "OtherPuzzleEditor". You do not provide a space and then the parameter.
You are supposed to pass the executable to launch and its parameters as separate arguments to the Start call. Change the code from this:
Process.Start(OtherPuzzleEditorPath & Space(1) & EditorPath)
对此:
To this:
Process.Start(OtherPuzzleEditorPath, EditorPath)
这篇关于如何使用process.start打开文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!