Skip Navigation LinksHome > Categories > Code from a Category

Reading and writing to file using ASP.NET and VB.NET

User Name: codelecturer
Name: Mike Chauhan
Contact Me:
Home Page:
6 years of total IT experience including programming, application development, System Maintenance . 3 years of Experienced and expertise in .Net Framework VB, Visual Basic.Net, ASP.Net 2.0, 3.5 and AD... [More]
Viewed Times: 4271
Add Date: 11/22/2012
In this article we will learn how to 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.

Happy Programming!!!

Post a Comment

Name: (Optional)
Email: (Optional, you can get an email if somebody replys your comments)*
Email me if somebody respons my comment below:
Enter Text
as Below:
(case insensitive, if hard to read, click the "get a new one" button)
* Your email address will not be shared with any third parties for any reason.
** Maximum 1000 charactors.