We Value Your Privacy

We and our partners use technology such as cookies on our site to personalise content and ads, provide social media features, and analyse our traffic. Click below to consent to the use of this technology across the web. You can change your mind and change your consent choices at anytime by returning to this site.

Update Consent
Loading ...

How to Create RTF Files With VB.Net

Updated July 19, 2017

The rich text format (RTF) provides you with a standardised method to customise fonts and colours for a text document. RTF is used to transfer files to different applications without losing the bold, italicised, underlined and colour fonts. You output to an RTF file using the RTF notation at the top and end of the file output from VB.NET.

Loading ...
  1. Click the Windows "Start" button, and select "All Programs." Click "Microsoft .NET," then click the "Visual Studio" shortcut to open the VB.NET programming software.

  2. Double-click the VB.NET project name to load the code in the software. Right-click the form you want to use to write to the file in "Solution Explorer" to open the code editor.

  3. You must create the file before you can write to it. The following code creates a file stream variable to create the file and open it:

  4. Dim file as System.IO.File

  5. Dim write as System.IO.StreamWriter

  6. write = file.CreateText("C:\rtf_file.rtf")

  7. Add text to the file. The following creates a basic RTF file:

  8. write.WriteLine("{\rtf1")

  9. write.WriteLine("Basic Text")

  10. write.WriteLine ("}")

  11. The first line of code indicates that the file is an RTF. You can place any text after this line of text. The final line of code closes the RTF format stream.

  12. After you finish writing to the file, you must close it. Add the final line of code to close the file:

  13. write.Close

Loading ...

About the Author

Jim Campbell has been a computer engineer for over five years. He excels in hardware repair, computer programming and troubleshooting, and software design. He is currently attending Florida Atlantic University, pursuing a master's degree in computer and electrical engineering and fine-tuning his technical writing abilities.

Loading ...