This This tutorial will show you how to write to a file on the disk using ASP.NET 2.0 and C#.NET

To write a simple file to the disk, we will need to first import the System.IO namespace. The System.IO namespace contains the StreamWriter type that we will use to perform our disk write.

We’ll put our code in the btnSubmit_Click() event.

When the btnSubmit_Click() event fires it executes the File.CreateText method with a parameter specifying the path and name of the file which we would like to write to, it also returns a StreamWriter object instance which we then execute the WriteLine and Close methods on.

The front end Default.aspx page looks something like this:

The flow for the code behind page as follows.

Download Source Files