Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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
0 Sergey Alexandrovich Kryukov 430
1 Gihan Liyanage 347
2 ClimerChinna 222
3 vikinghunter 176
4 OriginalGriff 151
0 Sergey Alexandrovich Kryukov 8,373
1 OriginalGriff 7,112
2 CPallini 2,598
3 Richard MacCutchan 2,025
4 Abhinav S 1,788


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 18 Nov 2012
Copyright © CodeProject, 1999-2014
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