[RESOLVED] load text file into richtextbox-VBForums
Results 1 to 8 of 8

Thread: [RESOLVED] load text file into richtextbox

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Location
    ohio, usa
    Posts
    719

    Resolved [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

  2. #2
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,116

    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!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Location
    ohio, usa
    Posts
    719

    Re: load text file into richtextbox

    Quote 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!!!

  4. #4
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,116

    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!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Location
    ohio, usa
    Posts
    719

    Re: [RESOLVED] load text file into richtextbox

    Quote 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!

  6. #6
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    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.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Location
    ohio, usa
    Posts
    719

    Re: [RESOLVED] load text file into richtextbox

    Quote 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!!

  8. #8
    Hyperactive Member boku's Avatar
    Join Date
    Dec 2004
    Posts
    386

    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
    -BoKu-

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.