2016-06-17 74 views
0

我在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 
+0

「文件標題」是指文件名嗎?那裏有很多與代碼無關的代碼。那個Form Load事件不起作用? – Plutonix

+0

'Me.Text =「SHDO v2.0 - 」&Path.GetFileName(My.Application.CommandLineArgs(0))' – LarsTech

+0

@Plutonix我編輯了這個問題並澄清了它,但是,我確實打算說「文件名」。我也刪除了不必要的代碼,並且表單加載事件起作用,我只需要幫助查找打開的文件的名稱。 – Odoglv1

回答

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代替。

希望幫助:)