Resources » .NET programming » .NET Framework

How to save contents of a RichText Box to .rtf file in VB.Net without using Save dialog Box


Posted Date: 12-May-2013  Last Updated:   Category: .NET Framework    
Author: Member Level: Gold    Points: 20


In this article I am going to show you how you can save contents of a RichText Box to .rtf file and also load the contents of that .rtf file to Rich Text Box in VB.Net without using Save or open dialog Box.



In this article I am going to show you how you can save contents of a RichText Box to .rtf file and also load the contents of that .rtf file to Rich Text Box in VB.Net without using Save or open dialog Box.
First of all create a new project and add a Rich Textbox and three buttons on the form as shown in image.
Now, change the name of richtext box1 to richtextbox and also change the name of three buttons as btnsave, btnclear and btnload respectively. Open the code window of the form and write the following code on the click events of the buttons.
Note:- you need to add Imports System.IO in the general section of the code window.

Imports System.IO

Public Class Form1

Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
File.WriteAllText("C:\sam.rtf", RichTextBox.Text)
End Sub

Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click
RichTextBox.Text = ""
End Sub

Private Sub btnload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnload.Click
RichTextBox.Text = File.ReadAllText("C:\sam.rtf")
End Sub
End Class


Finally press F5 to run the project.
Regards


Did you like this resource? Share it with your friends and show your love!

Responses to "How to save contents of a RichText Box to .rtf file in VB.Net without using Save dialog Box"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Subscribe to Subscribers
    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    Sandip Singh
    More...
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India