Read and write to file using ASP.NET (VB)
Reading and writing to the file content using ASP.NET 2.0 and C# 2.0 is actually very simple.

First, you will need to import the System.IO namespace.

The System.IO namespace contains types that allow reading and writing to files and data streams, and types that provide basic file and directory support. Using the class of File, and DirectoryInfo at here.

Use the DirectoryInfo class for typical operations such as copying, moving, renaming, creating, and deleting directories.

Use the File class for typical operations such as creating, opening, deleting, appending, copying, moving, and renaming to files.

Use the ReadAllText method to opens a text file, reads all lines of the file, and then closes the file.

Use the WriteAllText method Creates a new file, writes the specified string to the file, and then closes the file. If the target file already exists, it is overwritten.

We use the buttonDisplay_Click event to display the file content and use the buttonSave_Click even to save as a file.

The code as follows:

The front ReadWriteTextCSharp.aspx page looks something like this:

The flow for the code behind page is as follows:

Download Source Files