将文件名传递给程序

时间:2016-06-17 22:36:54

标签: vb.net

我正在VB.NET中创建一个应用程序,我试图将双击文件的名称传递给应用程序,因此我可以将应用程序的标题设置为它。我需要找到检索它的方法,但我似乎无法这样做。我只想知道,是否/如何检索在此应用程序中打开的文件的名称。

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Try
        TextBox1.Text = My.Computer.FileSystem.ReadAllText(My.Application.CommandLineArgs(0)) 'Set TextBox Text to file text
        Me.Text = "SHDO v2.0 - " + 'Here should go the opened file title
        editedYet = False 'Disable title asterisk
    Catch ex As Exception

    End Try
End Sub

1 个答案:

答案 0 :(得分:0)

你在这里:

    Dim filePath As String = My.Application.CommandLineArgs(0)
    TextBox1.Text = IO.File.ReadAllText(filePath)
    Me.Text = "SHDO v2.0 - " & IO.Path.GetFileName(filePath)

如果您不想要文件扩展名,可以改用IO.Path.GetFileNameWithoutExtension

希望有所帮助:)