PDA

Click to See Complete Forum and Search --> : Read file into richtextbox *[resolved]*


RealNickyDude
Dec 31st, 2002, 10:21 AM
How? I've searched the forum and came across this:


Dim fs As FileStream = New FileStream(Application.StartupPath & "\snippets.txt", IO.FileMode.Open)
Dim sw As New StreamWriter(fs)
sw.Write(rtbcodewindow.Text)
sw.Close()
fs.Close()


but nothing seems to happen!

I have a toolbar and pressing various buttons will load an associated rtf file, plain and simple, but how? I need the exact code as I can get bugger all to work!

:(

Pirate
Dec 31st, 2002, 10:34 AM
I'm sure ,this solves your problem .
http://abstractvb.com/code.asp?F=11&P=1&A=969

add this to your VB.NET Book

RealNickyDude
Dec 31st, 2002, 10:45 AM
I've taken this line from it pirate:

rtbcodewindow.LoadFile(Application.StartupPath & "\forms.rtf", RichTextBoxStreamType.RichText)Hoping that will do it (as they are set files, not chosen by the user) but i'm getting this error:

System.IO.FileNotFoundException' occurred in mscorlib.dll

:(

All i want is to load a specific file into a richtextbox, no filters, no user dialog boxes, no line-splitting, just a straight forward "load this rtf file into this rtb."

RealNickyDude
Dec 31st, 2002, 11:01 AM
It's ok, its all sorted now, I didn't have the textfiles in the right place (doh!) :rolleyes:

Pirate
Dec 31st, 2002, 11:43 AM
:cool: ,

MrPolite
Dec 31st, 2002, 01:13 PM
ahem ahem ahem, so many people make this mistake, in vb6 and in vb.net :(
when you use "Application.StartupPath" it sometimes returns the path without a "\" at the end, but NOT ALWAYS!
If you run your app from the root directory in drive C for example, it is going to return "C:\", WITH a backslash.....
so dont just use Application.StartupPath & "\"


You could just use IO.Path.Combine (Application.StartupPath, "filename")


:)

hellswraith
Dec 31st, 2002, 06:31 PM
Great tip MrPolite. I have never seen that before. Thanks

MrPolite
Dec 31st, 2002, 07:04 PM
Originally posted by hellswraith
Great tip MrPolite. I have never seen that before. Thanks hehe, same with app.path in vb6:D

RealNickyDude
Jan 1st, 2003, 05:42 AM
Originally posted by MrPolite
ahem ahem ahem, so many people make this mistake, in vb6 and in vb.net :(
when you use "Application.StartupPath" it sometimes returns the path without a "\" at the end, but NOT ALWAYS!
If you run your app from the root directory in drive C for example, it is going to return "C:\", WITH a backslash.....
so dont just use Application.StartupPath & "\"


You could just use IO.Path.Combine (Application.StartupPath, "filename")


:)
Could you tell me exactly how Mr Polite? and thanks for the tip. :)

Oh, and a Happy New Year to everyone! :D

MrPolite
Jan 1st, 2003, 02:04 PM
Happy new year! :)


can I tell you how to do what? use that path.combine? hmm

well you could do something like this:

Dim docPath As String = IO.Path.Combine(Application.StartupPath,"forms.rtf")

rtbcodewindow.LoadFile(docPath, RichTextBoxStreamType.RichText)


btw I havent tested that code, hope it works :)

RealNickyDude
Jan 4th, 2003, 07:05 AM
Works a treat Mr Polite :D