Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all I got a problem I am trying to open file and read the text to a form ok I open file I enter the text in rich textbox and I hit save now when I open the file again it blank ? this is the problem its not saving the text input so when I open a file in a Frmchild it should display the text.
<pre lang="c#">

  public partial class frmChild2 : Form
    {
        public frmChild2()
        {
            InitializeComponent();
        }
    
    public frmChild2 ( string fileName )
    : this()
    {

    Savefile(fileName);
    }
    private void Savefile ( string fileName )
    {

    string strExt;
    strExt = System.IO.Path.GetExtension(fileName);
    strExt = strExt.ToUpper();
    if (strExt == ".RTF")
    {

    richTextBox1.LoadFile(fileName, RichTextBoxStreamType.RichText);
    }
    else
    {

    System.IO.StreamReader txtReader;
    txtReader = new
    System.IO.StreamReader(fileName);
    richTextBox1.Text = txtReader.ReadToEnd();
    txtReader.Close();
    txtReader = null;
    richTextBox1.SelectionStart = 0;
    richTextBox1.SelectionLength = 30;
    }
    richTextBox1.Modified = true;
    this.Text = "Unit  9  Editor: " + fileName;
    }

    private void btnSave_Click(object sender, EventArgs e)
    {
                  SaveFileDialog savefileDialog = new  SaveFileDialog();
            savefileDialog.DefaultExt = "txt";
            savefileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            savefileDialog.Filter = "Text Files (*.txt)|*.txt|Html Files (*.htm)|*.htm|Rich Text Files (*.rtf)|*.rtf|All Files (*.*)|*.*";
            savefileDialog.FilterIndex = 1;
            savefileDialog.FileName = string.Empty;
            if (savefileDialog.ShowDialog(this) == DialogResult.OK && savefileDialog.FileName != String.Empty)
            {

                Form frmChild = new frmChild2 (savefileDialog.FileName);
                frmChild = this;
                frmChild.Show();
            }
            else
            {

                MessageBox.Show("Save File request cancelled by user.", "Cancelled");
            }
        }
    } 
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900