opening files from outside my application (vb.net 2.0)

I have a program that reads .txt and .rtf files, I have made an installer project for the program within vs2005 and I have put the file type and set the command in 'files types' to 'Primary output from OSSUniType (Release Any CPU)'.

Now when I compile my program i look in a folder that has .rtf in it and it shows the icon to my file as expected but when I open it from windowsmy program launches but no text is shown but if I open from windows into notepad or word the text is shown.

If I run my program then click 'open' and find the exact same file then the text is shown.

also in file types 'arguments' is shown as "%1"



Answer this question

opening files from outside my application (vb.net 2.0)

  • EtasystemiCKB

    I tried this:

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    If Environment.GetCommandLineArgs.Equals("%1") = True Then

    Dim open As New clsMenu 'calls class

    open.metOpen() 'uses open method

    End If

    End Sub

    The above code did the same thing as in my first post, do you know where I m going wrong


  • KGW

    Does your program handle the arguments passed to it

    When the main form opens, you have to check Environment.GetCommandLineArgs. It contains the file name passed via the "%1", and you need to call your method to load a file.



  • Marwan

    GetCommandLineArgs returns a string array, and the place holder %1 has been replaced with the file name the user has selected in Explorer.

    If (Environment.GetCommandLineArgs.Length > 1) Then

    Dim s As String = Environment.GetCommandLineArgs(1)

    ' Open file s

    End If

    (The string at index 0 is the file of your application)



  • jaydeep ahuja

    Thanks alot, incase someone reads this, this snippet worked for me:

    Try

    Dim s As String = Environment.GetCommandLineArgs(1)

    If (Environment.GetCommandLineArgs.Length > 1) Then

    If s.Contains(".txt") Then

    Me.rtfMainText.LoadFile(s, RichTextBoxStreamType.PlainText)

    Me.Text = s

    Else

    Me.rtfMainText.LoadFile(s)

    Me.Text = s

    End If

    End If

    Catch ex As Exception

    End Try

     


  • opening files from outside my application (vb.net 2.0)