Click here to Skip to main content
12,944,121 members (54,997 online)
Rate this:
 
Please Sign up or sign in to vote.
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 18-Nov-12 15:24pm
leetank161

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,653
CHill60 2,970
Maciej Los 2,388
Jochen Arndt 1,900
ppolymorphe 1,765


Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 18 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100