Sams Teach Yourself ASP.NET in 21 Days, Second Edition By Chris Payne
Table of Contents
Day 13. Reading and Writing Files on the Web Server
This workshop will help reinforce the concepts I've covered in today's lesson. It is very helpful to understand fully the answers before moving on. Answers can be found in Appendix A.
What is the difference between a file and a stream?
What are the six FileMode values?
What does the Peek method do, and why is it helpful?
How do you verify the existence of a file or directory on a server?
Use the File object to open a file called userdata.txt in the root directory of your c: drive, for appending. If this file doesn't exist, use the File object to create it, and make sure that no other applications can access this file while you are using it.
Create an ASP.NET page that will open a file specified by a user in a text box, and display the contents in a label. Make sure to check whether the file exists. Note that the user must be required to enter the full path to the file as well.
Modify Exercise 1 so that the content of the file is displayed in an editable text box. Allow the user to make changes, and when the user clicks a submit button, write the changes back to the file.