Odoglv1 Odoglv1 -5 years ago 195
Vb.net Question

Pass File Name to Program

I am making an application in VB.NET and I am attempting to pass the double-clicked file's name into the application, so I can set the application's title to it. I need to find the method to retrieve this, yet I cannot seem to do so. I just want to know, really, if/how I can retrieve the name of the file that was opened in this application.

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
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

Answer Source

Here you are:

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

Hope that helps :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download