打开Application Path +特定文件夹的按钮

时间:2013-10-10 18:24:34

标签: vb.net visual-studio-2008

我对如何做到这一点很困惑。我想要做的是当我点击Button1时,我的程序将在资源管理器中打开一个文件夹,第二个按钮将打开一个文件作为文本文件。

这是我的代码:

按钮1

   Process.Start("explorer.exe", Application.ExecutablePath + "\mvram.biz")

按钮2

   Process.Start("Notepad.Exe", "README.txt")

我的问题是每次点击按钮都会打开我的文档。它必须打开APPpath +特定文件夹。

编辑:

Public Class Form1



Private Sub ExcisionButtonDefault5_Click(ByVal sender As System.Object, ByVal e As  System.EventArgs) Handles ExcisionButtonDefault5.Click
    Me.Close()
End Sub

Private Sub ExcisionButtonDefault1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExcisionButtonDefault1.Click
    Dim path As String = System.IO.Path.GetDirectoryName(Application.ExecutablePath) & "\mvram.biz\"
    Process.Start("explorer.exe", path)
End Sub

Private Sub ExcisionButtonDefault2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExcisionButtonDefault2.Click
    Process.Start("explorer.exe", Application.StartupPath & "\Documents")
End Sub

Private Sub ExcisionButtonDefault3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExcisionButtonDefault3.Click
    Process.Start("Notepad.Exe", "/select," & "README.txt")
End Sub

Private Sub ExcisionButtonDefault4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExcisionButtonDefault4.Click
    Process.Start("explorer.exe", System.Windows.Forms.Application.StartupPath + "\Presentation")
End Sub

Private Sub ExcisionButtonDefault6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExcisionButtonDefault6.Click
    System.Diagnostics.Process.Start("http://www.mvram.biz")
End Sub
End Class

2 个答案:

答案 0 :(得分:0)

要在FileExplorer中打开特定文件夹,您可以尝试传递此参数:

Dim x as string = "FolderPath"
Process.Start("explorer.exe", "/root,x")

或者您可以传递参数"/select,x",它将打开文件资源管理器,其中包含所选文件夹但未打开。这article可能会有所帮助。或者您可以像上面尝试的那样拥有文件地址,它将打开到正确的位置。

然后打开一个txt文件,您需要做的就是:

Process.Start("FileAddress")

这将在默认编辑器中打开文件。

HTH

答案 1 :(得分:0)

它打开随机位置的原因是因为您打算执行错误的路径(整个应用程序路径+其他应用程序)。你必须选择目录。试试这段代码:

Dim path As String = System.IO.Path.GetDirectoryName(Application.ExecutablePath) & "\mvram.biz"
Process.Start("explorer.exe", path)

其他选择:

Dim path As String = Environment.CurrentDirectory & "\mvram.biz"

我个人更喜欢使用绝对路径而不是相对路径(只是引用同一目录时的文件名)。