Question: Hello in C# please complete, Assignment 1 7 - 1 Work with a text file In this exercise, you'll add code to an Inventory Maintenance
Hello in C# please complete, Assignment Work with a text file
In this exercise, you'll add code to an Inventory Maintenance app that reads data from and writes data to a text file.
Open the InventoryMaintenance project in the ExtraStarts backslash mathrmChbackslash
InventoryMaintenanceText directory, and display the code for the InventoryDB class.
Add code to the GetItems method that creates a StreamReader object with a FileStream object for the InventoryItems.txt file that's included in the project. The Path constant contains the path to this file. The file should be opened if it exists or created if it doesn't exist, and it should be opened for reading only.
Add code that reads each record of the text file, stores the fields, which are separated by pipe characters, in an InventoryItem object, and adds the object to the List object. Then, close the StreamReader object.
Add code to the SaveItems method that creates a StreamWriter object with a FileStream object for the InventoryItems.txt file. The file should be created if it doesn't exist or overwritten if it does exist, and it should be opened for writing only.
Add code that writes each InventoryItem object in the Listobject to the text file, separating the fields with pipe characters. Then, close the StreamWriter object.
Test the app to be sure it works correctly.
Update the GetItems and SaveItems methods to use using declarations to automatically close the StreamReader and StreamWriter objects. Then, delete the statements that explicitly close these objects.
Test the app again to be sure it works correctly.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
