Notepad - opening a file, Saving a file
private void Open_Click(object sender, System.EventArgs e)
{
try
{
openFileDialog1.ShowDialog();
fileName = openFileDialog1.FileName;
StreamReader stReader = new StreamReader(fileName);
TextArea.Text = stReader.ReadToEnd();
checkText = false;
stReader.Close();
this.Text = fileName + " - Notepad";
fileName = "";
}
catch{
}
}
private void saveFile()
{
if ( fileName == "")
{
saveFileDialog1.Filter = "TEXT Documents. (*.txt)*.txtAll files*.*";
DialogResult resVal = saveFileDialog1.ShowDialog();
if ( resVal == DialogResult.Cancel )
{
return;
}
fileName = saveFileDialog1.FileName;
this.Text = fileName + " - Notepad";
}
try
{
StreamWriter stWriter = new StreamWriter(fileName);
stWriter.WriteLine(TextArea.Text);
stWriter.Flush();
stWriter.Close();
checkText = false;
}
catch
{
MessageBox.Show(this, "The file "+fileName+" is Read only. \n\n File Could not saved.", "Notepad", MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
return;
}
}

0 Comments:
Post a Comment
<< Home