-
Mar 30th, 2008, 01:33 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] load text file into richtextbox
I get this error: "file format is not valid"
can this be fixed? if so, could someone point me the way or give me some more code?
Code:
Dim OpenFile1 As New OpenFileDialog
OpenFile1.Filter = "txt Files (Text Files)|*.txt"
OpenFile1.Title = "Open a Document."
If (OpenFile1.ShowDialog = System.Windows.Forms.DialogResult.OK) Then
RichTextBox1.LoadFile(OpenFile1.FileName)
End If
-
Mar 30th, 2008, 01:40 PM
#2
Re: load text file into richtextbox
Try specifying the file type. If its a plain clear textfile then...
Code:
Me.RichTextBox1.LoadFile("C:\Test.txt", RichTextBoxStreamType.PlainText)
and if its an actual rtf file then....
Code:
Me.RichTextBox1.LoadFile("C:\Test.rtf", RichTextBoxStreamType.RichText)
Last edited by RobDog888; Mar 30th, 2008 at 01:52 PM.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Mar 30th, 2008, 01:44 PM
#3
Thread Starter
Fanatic Member
Re: load text file into richtextbox
Originally Posted by RobDog888
Try specifying the file type. If its a plain clear textfile then...
Code:
Me.RichTextBox1.LoadFile("C:\Test.txt", RichTextBoxStreamType.PlainText)
and if its an actual rtf file then....
Code:
Me.RichTextBox1.LoadFile("C:\Test.txt", RichTextBoxStreamType.RichText)
Thanks!!!
that fixed it!!!
-
Mar 30th, 2008, 01:50 PM
#4
Re: [RESOLVED] load text file into richtextbox
Oops, I did a copy/paste error. I didnt change the txt extension if its an actual rtf file. should be Test.rtf.
You could add filters to your filedialog and select case after based upon the extension to determine which type of encoding to apply when loading.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Mar 30th, 2008, 01:51 PM
#5
Thread Starter
Fanatic Member
Re: [RESOLVED] load text file into richtextbox
Originally Posted by RobDog888
Oops, I did a copy/paste error. I didnt change the txt extension if its an actual rtf file. should be Test.rtf.
You could add filters to your filedialog and select case after based upon the extension to determine which type of encoding to apply when loading.
I caught it.
thanks!
-
Mar 30th, 2008, 03:19 PM
#6
Frenzied Member
Re: [RESOLVED] load text file into richtextbox
Sorry i couldnt really explain before i was in a rush
the reason i suggested it in the other thread was because i re-created microsoft word lol and i just gave you the code i used for the open function. you can create your own file-type but only your program will be able to read it.
-
Mar 30th, 2008, 03:20 PM
#7
Thread Starter
Fanatic Member
Re: [RESOLVED] load text file into richtextbox
Originally Posted by noahssite
Sorry i couldnt really explain before i was in a rush
the reason i suggested it in the other thread was because i re-created microsoft word lol and i just gave you the code i used for the open function. you can create your own file-type but only your program will be able to read it.
ok and thanks!!
-
May 9th, 2008, 10:04 AM
#8
Hyperactive Member
Re: [RESOLVED] load text file into richtextbox
why wont this work
Dim openthisfile As String
openthisfile = (Application.StartupPath & "\files" & sbFile.Text)
If sbFile.Text > "" Then
Me.rtbText.LoadFile(openthisfile, RichTextBoxStreamType.PlainText Or RichTextBoxStreamType.RichText)
End If
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
|