3 Replies - 2881 Views - Last Post: 23 March 2010 - 01:15 PM Rate Topic: -----

#1 wuu  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 85
  • Joined: 16-March 09

Saving RichTextBox and other content into one file

Posted 23 March 2010 - 12:27 PM

Hi all!

I was wondering, if there is an easy way, to save RichTextBox content and other data, of type let say int into one file, binary perhaps, and then load it again?
Is This A Good Question/Topic? 0
  • +

Replies To: Saving RichTextBox and other content into one file

#2 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: Saving RichTextBox and other content into one file

Posted 23 March 2010 - 12:42 PM

Do you mean like saving styling as well or just a plain text? You could use the StreamWriter to write plain text to a file in read it back with StreamReader. If you need to save data in binary format I think there is some BinaryWriter (not really sure about that)...
Was This Post Helpful? 0
  • +
  • -

#3 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 528
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: Saving RichTextBox and other content into one file

Posted 23 March 2010 - 01:05 PM

This may help you:
http://msdn.microsof...28VS.71%29.aspx
Was This Post Helpful? 0
  • +
  • -

#4 wuu  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 85
  • Joined: 16-March 09

Re: Saving RichTextBox and other content into one file

Posted 23 March 2010 - 01:15 PM

View PostFlashM, on 23 March 2010 - 11:42 AM, said:

Do you mean like saving styling as well or just a plain text? You could use the StreamWriter to write plain text to a file in read it back with StreamReader. If you need to save data in binary format I think there is some BinaryWriter (not really sure about that)...


I need to save styling as well; else wise I would use normal textbox.
I found a need solution to my problem. I found out that I can get styling as well form RichTexBox using RichTexBox.Rtf.
So I wrote this in binary file first and on the end of that string I wrote my integer numbers.
Code looks like this and its working fine:

Code for saving file:

            if (saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
               saveFile1.FileName.Length > 0)
            {
                FileStream FS = new FileStream(saveFile1.FileName, FileMode.OpenOrCreate);
                BinaryWriter BW = new BinaryWriter(FS);

                BW.Write(richTextBox1.Rtf);
                foreach(int i in razmik)
                {
                    BW.Write(i);
                }
                FS.Close();
            }



Code for loading file:

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                FileStream FS = new FileStream(openFileDialog1.FileName, FileMode.Open);
                BinaryReader BR = new BinaryReader(FS);
                           
                richTextBox1.Rtf = BR.ReadString();
                razmik.Clear();
                for (int i = 0; i < richTextBox1.Lines.Length; i++)
                {
                    razmik.Add(BR.ReadInt32());
                }
                FS.Close();
            }


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1