Results 1 to 11 of 11

Thread: Load a textfile into a textbox when dubble clicked?[Resolved]

  1. #1

    Thread Starter
    Member JesusFreak's Avatar
    Join Date
    Feb 2003
    Location
    Headed for Heaven
    Posts
    57

    Question Load a textfile into a textbox when dubble clicked?[Resolved]

    How do you make is so that if you dubble click a textfile with a certain extision it opens your program with the data loaded?

    ex.
    Say you have a textbox
    and a file called "test.me"
    and if you open "test.me" then
    it would open the program with the contents of "test.me" in the textbox?
    Last edited by JesusFreak; Mar 1st, 2003 at 11:38 AM.
    That if you confess with your mouth, "Jesus is Lord," and believe in your heart that God raised him from the dead, you will be saved.

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    you need to do a few things:

    like one: associate your app to the file type.
    I have found this http://www.developerfusion.com/show/36/2/
    which should give you some direction on what to do..(you'll have to figure out how to convert it to vb.net)

    then allow your app to take a commandline argument.
    that arg will be the file name..pull it in and open/drop it into the textbox

    look into this for command line args maybe?
    System.Environment.CommandLine

    good luck
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Member JesusFreak's Avatar
    Join Date
    Feb 2003
    Location
    Headed for Heaven
    Posts
    57
    Code:
         Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If System.Environment.CommandLine <> "C:\vbnetsbs\chap12\Xor Encryption\bin\Xor Encryption.exe" Then
                txtNote.LoadFile(System.Environment.CommandLine)
            End If
        End Sub
    txtNote is a Ritch Text Box.
    If I drop a Rich Text file into the application then it says:
    Illegal Characters in path.
    What am I doing wrong?
    That if you confess with your mouth, "Jesus is Lord," and believe in your heart that God raised him from the dead, you will be saved.

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    test whats comming in by using say a msgbox

    my guess is that you need to parse out the filename off the end of the command line..then just load that...you passing in the program and the file into the richtextbox

    Just a guess...
    since i havent tried this yet
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    Dim temp As String
    Dim cmdlne() As String
    temp = System.Environment.CommandLine
    cmdlne = Split(temp, """")
    MsgBox(cmdlne(3))

    got the name of the file passed in


    so replace MsgBox(cmdlne(3))
    with
    txtNote.LoadFile(cmdlne(3))



    (not bod for someone who has been using .net for only a week )
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  6. #6

    Thread Starter
    Member JesusFreak's Avatar
    Join Date
    Feb 2003
    Location
    Headed for Heaven
    Posts
    57
    When I run that I get this error:
    Index was outside the bounds of the array.

    If I do this:
    txtNote.Load(CommandLine)
    and CommandLine = "C:\Test\test.rtf" then I get this error:
    Illegal Characters in path.
    But if I do this:
    Dim CommandString as String
    CommandString = "C:\Test\test.rtf"
    txtNote.Load(CommandString) then it works fine.
    That if you confess with your mouth, "Jesus is Lord," and believe in your heart that God raised him from the dead, you will be saved.

  7. #7
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    ok..found this: much better..more acurate

    Dim cmdlne() As String
    cmdlne = System.Environment.GetCommandLineArgs

    cmdlne(0) will be the path of your app
    cmdlne(1) will be the path of the file passed in


    System.Environment.GetCommandLineArgs
    passes an array of all args passed into your app


    soooo...try this

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim cmdlne() As String
    3.         cmdlne = System.Environment.GetCommandLineArgs
    4.         If UBound(cmdlne) > 0 Then
    5.             If System.IO.File.Exists(cmdlne(1)) Then
    6.                 txtNote.LoadFile(cmdlne(1))
    7.             End If
    8.         End If
    9.     End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  8. #8
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    ok I tested it..and it works...BUT

    you need to test the filetype

    I tried it with a txt file and had to change this line:
    txtNote.LoadFile(cmdlne(1), RichTextBoxStreamType.PlainText)

    soo...i'll see if i can figure out how to check the file type
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  9. #9
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    not sure if there is a better way...but this works:

    (im sure there is probably a better way...)

    but this will load the file no matter wah..and ignore an "wrong filetype" errors


    VB Code:
    1. Dim cmdlne() As String
    2.         cmdlne = System.Environment.GetCommandLineArgs
    3.         If UBound(cmdlne) > 0 Then
    4.             If System.IO.File.Exists(cmdlne(1)) Then
    5.                 Try
    6.                     txtNote.LoadFile(cmdlne(1), RichTextBoxStreamType.PlainText)
    7.                     txtNote.LoadFile(cmdlne(1), RichTextBoxStreamType.RichNoOleObjs)
    8.                     txtNote.LoadFile(cmdlne(1), RichTextBoxStreamType.RichText)
    9.                     txtNote.LoadFile(cmdlne(1), RichTextBoxStreamType.TextTextOleObjs)
    10.                     txtNote.LoadFile(cmdlne(1), RichTextBoxStreamType.UnicodePlainText)
    11.  
    12.                 Catch Ex As Exception
    13.  
    14.                 End Try
    15.  
    16.             End If
    17.         End If
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  10. #10

    Thread Starter
    Member JesusFreak's Avatar
    Join Date
    Feb 2003
    Location
    Headed for Heaven
    Posts
    57
    Thanks!

    It only works for text files but that's good enough.
    That if you confess with your mouth, "Jesus is Lord," and believe in your heart that God raised him from the dead, you will be saved.

  11. #11
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    cool..glad I could help.
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width