Results 1 to 3 of 3

Thread: Save and opening a file using a RichTextBox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Posts
    159

    Question Save and opening a file using a RichTextBox

    Hey ppl

    I'm a having a little bit of trouble with opening and saving a file in a richtextbox. I have created the both codes here is the code for both

    ------------------------------------------------------------------------------------
    Open
    ------------------------------------------------------------------------------------

    Code:
            Private Sub MenuItemFileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemFileOpen.Click
    
            Dim openFile1 As New OpenFileDialog
    
            openFile1.DefaultExt = "*.rtf"
            openFile1.Filter = "RTF Files|*.rtf"
    
            If (openFile1.ShowDialog() = System.Windows.Forms.DialogResult.OK) And (openFile1.FileName.Length > 0) Then
    
                RichTextBox1.LoadFile(openFile1.FileName)
            End If
    
        End Sub
    ------------------------------------------------------------------------------------
    Save File
    ------------------------------------------------------------------------------------

    Code:
        Private Sub MenuItemFileSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemFileSave.Click
    
            Dim saveFile1 As New SaveFileDialog
    
            saveFile1.DefaultExt = "*.rtf"
            saveFile1.Filter = "RTF Files|*.rtf"
    
            If (saveFile1.ShowDialog() = System.Windows.Forms.DialogResult.OK) And (saveFile1.FileName.Length) > 0 Then
    
                RichTextBox1.SaveFile(saveFile1.FileName, RichTextBoxStreamType.PlainText)
    
            End If
    
        End Sub

    I can open rtf documents made in word but if i save then open rtf files saved in my programm it gives me an error "Invalid File Format" I'm not realy sure where i'm going wrong please can you help?

    Thanks

    James

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    RichTextBox1.SaveFile(saveFile1.FileName, RichTextBoxStreamType.PlainText)
    you need to specify a richtextbox streamtype when loading the file. eg:
    VB Code:
    1. RichTextBox1.LoadFile(openFile1.FileName, RichTextBoxStreamType.RichText)
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Posts
    159

    Question

    Thanks for the help just got 1 more question

    once i save the file i want the caption of form 1 to be the following

    My Editor: fileName

    But what i get is

    My Editor: C:\Documents and Settings\Desktop\Test.rtf

    is there anyway to just get the Test.rtf

    Here's my code any suggestions will be greatfull

    Code:
    Dim saveFile1 As New SaveFileDialog
            Dim fileName As String
    
            saveFile1.DefaultExt = "*.rtf"
            saveFile1.Filter = "RTF Files|*.rtf"
    
            If (saveFile1.ShowDialog() = System.Windows.Forms.DialogResult.OK) And (saveFile1.FileName.Length) > 0 Then
    
                RichTextBox1.SaveFile(saveFile1.FileName)
                fileName = saveFile1.FileName
                Me.Text = "My Editor: " + fileName
                saveCheck = False

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