Reading and Writing to a Text File

To illustrate the use of streams, I will walk you through creating a simple Windows Forms application that reads in and writes out text files. Of course, text files (and even files in general) are just one example of streams. The code to work with streams is generic enough that the same techniques demonstrated in this sample to read and write files would work against something more interesting such as a MemoryStream.

Configuring a New Windows Application

For the first step, create a new Windows Forms project. Call it ReadWriteFile. Add one each of the MainMenu, OpenFileDialog, SaveFileDialog, and TextBox controls to the form. Set the properties as in Table 4.3, by selecting each control and then changing the ...

Get Microsoft® Visual Basic® .NET 2003 Kick Start now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.