Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

By using C sharp Programming, create a note reading and writing application. The

ID: 3670584 • Letter: B

Question

By using C sharp Programming, create a note reading and writing application. The application will have three buttons: Clear, Add, Read. The Clear button will empty the file. The Add button will take information in the textboxes and append it to the file. The Read button will read the complete file. Place extra lines and spacing when writing to your file to space out the different messages that have been added to the file. Include textboxes to accept the user's name, a title for the message, and the message itself.

Explanation / Answer

/*

In this Code Example.txt is an assuming text file. btnClear_Click is a clear button which will empty file. btnAdd_Click will add data into file using streamwriter class from richTxtMsg textbox. btnRead_Click will read data into file.

*/

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.IO;

{

public partial class Form1 : Form

{

string path = @"E:Example.txt";

public Form1()

{

InitializeComponent();

}

private void btnClear_Click(object sender, EventArgs e)

{

File.WriteAllText(path, string.Empty);

}

private void btnAdd_Click(object sender, EventArgs e)

{

if (!File.Exists(path))

{

File.Create(path).Dispose();

}

using (StreamWriter sw = File.AppendText(path))

{

sw.WriteLine("");

sw.WriteLine(txtMsgTitle.Text + " by - " + txtUserName.Text);

sw.WriteLine(richTxtMsg.Text);

}

}

private void btnRead_Click(object sender, EventArgs e)

{

richTxtMsg.Text = File.ReadAllText(path);

}

}

}