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;
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s