Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

QS: Using the System.IO in C#, Create a graphical application of your choice to demonstrate the use of READ and WRITE operations like we did

QS: Using the System.IO in C#, Create a graphical application of your choice to demonstrate the use of READ and WRITE operations like we did in LAB#5. Be Creative.

Submit a Word Document with the Design and the Code.

For Reference:

Lab # 5: C# File Management Solution

Problem Description:

READ: Create a program to display all the contents of a text file on screen (note: you must use a StreamReader). The name of the file will be entered in the command line.

WRITE: Create a program to ask the user for several sentences until they just press Enter (empty sentence) and store them in a text file named "test.txt"

Solution:

GUI

image text in transcribed

Coding

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.IO;

namespace FileRead

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

string fileName = Microsoft.VisualBasic.Interaction.InputBox("Enter the Name of the File", "File Name", "", 50, 100);

label1.Text = label1.Text + fileName;

StreamReader myFile;

try

{

myFile = File.OpenText(fileName);

string line = "";

do

{

line = myFile.ReadLine();

if (line != null)

{

richTextBox1.AppendText(Environment.NewLine + line);

}

} while (line != null);

}catch(IOException)

{

MessageBox.Show("File Does not Exit", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);

}

}

}

}

II.

image text in transcribed

Coding:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.IO;

namespace FileWrite

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

StreamWriter myFile;

string fileName = Microsoft.VisualBasic.Interaction.InputBox("What do you want to name your File", "File Name", "", 50, 100);

myFile = File.CreateText(fileName);

try

{

for (int i = 0; i

{

myFile.WriteLine(richTextBox1.Lines[i]);

}

}

catch (IOException)

{

MessageBox.Show("File Writing Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);

}

myFile.Close();

MessageBox.Show("Creating the File "+fileName+" Was Successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}

}

}

File Read Application File Details Enter File File Name File Content File Read Application File Details Enter File File Name File Content

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Bioinformatics Databases And Systems

Authors: Stanley I. Letovsky

1st Edition

1475784058, 978-1475784053

More Books

Students also viewed these Databases questions

Question

Evaluate 3x - x for x = -2 Answer:

Answered: 1 week ago