|
-
Feb 28th, 2003, 11:47 AM
#1
Thread Starter
Member
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.
-
Feb 28th, 2003, 12:59 PM
#2
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"
-
Feb 28th, 2003, 04:21 PM
#3
Thread Starter
Member
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.
-
Feb 28th, 2003, 08:38 PM
#4
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"
-
Feb 28th, 2003, 08:48 PM
#5
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"
-
Feb 28th, 2003, 09:44 PM
#6
Thread Starter
Member
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.
-
Feb 28th, 2003, 10:11 PM
#7
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:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cmdlne() As String
cmdlne = System.Environment.GetCommandLineArgs
If UBound(cmdlne) > 0 Then
If System.IO.File.Exists(cmdlne(1)) Then
txtNote.LoadFile(cmdlne(1))
End If
End If
End Sub
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Feb 28th, 2003, 10:15 PM
#8
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"
-
Feb 28th, 2003, 10:23 PM
#9
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:
Dim cmdlne() As String
cmdlne = System.Environment.GetCommandLineArgs
If UBound(cmdlne) > 0 Then
If System.IO.File.Exists(cmdlne(1)) Then
Try
txtNote.LoadFile(cmdlne(1), RichTextBoxStreamType.PlainText)
txtNote.LoadFile(cmdlne(1), RichTextBoxStreamType.RichNoOleObjs)
txtNote.LoadFile(cmdlne(1), RichTextBoxStreamType.RichText)
txtNote.LoadFile(cmdlne(1), RichTextBoxStreamType.TextTextOleObjs)
txtNote.LoadFile(cmdlne(1), RichTextBoxStreamType.UnicodePlainText)
Catch Ex As Exception
End Try
End If
End If
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Mar 1st, 2003, 11:37 AM
#10
Thread Starter
Member
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.
-
Mar 1st, 2003, 08:41 PM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|