Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8735011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:57:29+00:00 2026-06-13T09:57:29+00:00

I write some codes for simple text editor in C# and I use rich

  • 0

I write some codes for simple text editor in C# and I use rich text box control, I found a problem that I can’t solve. The problem is when I save a file in my text editor and then try to reopen it using windows notepad, it become in one line, this is the example

This is when I write and save from my app

enter image description here

After I save it and open in windows notepad it becomes like this
enter image description here

here are my code for saving a fie

try
{
    saveFileDialog1.ShowDialog();
    this.Text = file = toolStripTextBox1.Text = saveFileDialog1.FileName;
    isi = richTextBox1.Text;
    write = new System.IO.StreamWriter(file);
    write.WriteLine(isi);
    write.Close();
    toolStripStatusLabel2.Text = "Saved";
}
catch (Exception)
{
    toolStripStatusLabel2.Text = "Save cancelled by user";
}

do you have any idea how to fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:57:30+00:00Added an answer on June 13, 2026 at 9:57 am

    You are probably getting this because you are trying to save richTextBox1.Text (the whole text) in one line only using the following code

    isi = richTextBox1.Text;
    write = new System.IO.StreamWriter(file);
    write.WriteLine(isi);
    write.Close();
    

    It’s recommended to use write.WriteLine() on a specific line number in richTextBox1 then move to another line.

    Example

     for (int i = 0; i < richTextBox1.Lines.Length; i++)
     {
          write.WriteLine(richTextBox1.Lines[i]);
     }
    write.Close();
    

    Another Solution


    There’s already a built-in function for RichTextBox to save a file with a specific encoding. You may use RichTextBox.SaveFile() for this purpose.

    Example

    RichTextBox.SaveFile(string path, RichTextBoxStreamType);
    

    Where path represents saveFileDialog1.FileName in your code. For RichTextBoxStreamType, it’s best to set it as RichTextBoxStreamType.PlainText as long as you do not use RTF such as Color/Font/Protection/Indent/etc…

    Then, you may read the file again using the following method

    RichTextBox.LoadFile(string path, RichTextBoxStreamType);
    

    NOTICE: If the file is not in RTF and you try to read it in RTF (RichTextBox.LoadFile(string path, RichTextBoxStreamType.RichText);)
    you may encounter formatting errors. In this case, you’ll need to catch the exception and read the file in a Plain or Unicode encoding.

    Example

    RichTextBox _RichTextBox = new RichTextBox();
    try
    {
         _RichTextBox.LoadFile(@"D:\Resources\text.txt", RichTextBoxStreamType.RichText);
    }
    catch (Exception EX)
    {
         if (EX.Message.ToLower().Contains("format is not valid"))
         {
              _RichTextBox.LoadFile(@"D:\Resources\text.txt", RichTextBoxStreamType.PlainText);
         }
    }
    

    Thanks,

    I hope you find this helpful 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do you guys write comments on some simple code that you use just
I am trying to write some simple code which will read a text file
Question simple and quick: I have started to use Netbeans to write some code
I'm learning android now, and i write some simple codes according to the book.
Can someone write some sample code to explain this concept? I know what a
I wrote some codes so as to send e mail but I can only
I am trying to write some code that will generate accurate .proto files from
I'm trying to write some code for my database to enable a dropdown box
I am not an experienced Java programmer and i'm trying to write some text
I'm trying to create a simple WYSIWYG editor that will allow users to select

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.