Hi,
I am writing a program which will be able to save richtextbox contents and then load them back. I have been able to save and load without problem, until i thought that it wont handle multiple lines.
When i use multiple rows and save it, the txt file shows it all on one row, but when i load it back, it treats the text as separate rows.
Eg. in rtb1 i have:
Text
Text
Text
rtb2 has
Text2
This saves in a txt file as
TextTextText
Text2
When i load back, it is recognising the line breaks.
The problem is, when using StreamReader to read the lines back, I cant determine how many lines belong to that richtextbox (rtb). I figured i can concatenate a symbol to the start and end of rtb1 contents when it is saved and then load the contents for the particular rtb between the two points (saves as $TextTextText$). Thats where i am having trouble. How can i tell the program to load the text between the symbols into the richtextbox?
I have left out the unimportant code.
	
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
When loading the file and adding the lines, $Text goes in rtb1, Text in rtb2, Text$ in rtb3 and Text2 in rtb4. Text Text Text with line breaks (and without the symbols) should go in rtb1 and Text2 in rtb2 (rtb3 and 4 are empty in the example). I figure I need to use IndexOf or Contains, but i couldn't make it work.
Help would be appreciated.
	
		
			
		
		
	
				
			I am writing a program which will be able to save richtextbox contents and then load them back. I have been able to save and load without problem, until i thought that it wont handle multiple lines.
When i use multiple rows and save it, the txt file shows it all on one row, but when i load it back, it treats the text as separate rows.
Eg. in rtb1 i have:
Text
Text
Text
rtb2 has
Text2
This saves in a txt file as
TextTextText
Text2
When i load back, it is recognising the line breaks.
The problem is, when using StreamReader to read the lines back, I cant determine how many lines belong to that richtextbox (rtb). I figured i can concatenate a symbol to the start and end of rtb1 contents when it is saved and then load the contents for the particular rtb between the two points (saves as $TextTextText$). Thats where i am having trouble. How can i tell the program to load the text between the symbols into the richtextbox?
I have left out the unimportant code.
			
				C#:
			
		
		
		private void btnPDSave_Click(object sender, EventArgs e)
        {
            
                StreamWriter savePD = new StreamWriter("C:\savedfile.txt");
                savePD.WriteLine("$" + rtb1.Text + "$");
                savePD.WriteLine(rtb2.Text);
                savePD.WriteLine(rtb3.Text);
                savePD.WriteLine(rtb4.Text);
                savePD.Close();
        }
private void btnPDLoad_Click(object sender, EventArgs e)
        {
            
                string filename = ""; //create variable for the filename
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    filename = openFileDialog1.FileName; //filename = the full path name
                    using (StreamReader loadPD = File.OpenText(filename))
                    {
                        
                        rtb1.Text = loadPD.ReadLine(); //this reads the saved line
                        rtb2.Text = loadPD.ReadLine();
                        rtb3.Text = loadPD.ReadLine();
                        rtb2.Text = loadPD.ReadLine();
                    }
                }
                else
                { 
                }
            
        }When loading the file and adding the lines, $Text goes in rtb1, Text in rtb2, Text$ in rtb3 and Text2 in rtb4. Text Text Text with line breaks (and without the symbols) should go in rtb1 and Text2 in rtb2 (rtb3 and 4 are empty in the example). I figure I need to use IndexOf or Contains, but i couldn't make it work.
Help would be appreciated.
 
	 
 
		