This tutorial will show you how to generate static page using ASP.NET 2.0 and C#. At first, you will need to import the namespace from System.IO. 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. Class StringWriter which implements a TextWriter for writing information to a string. The information is stored in an underlying StringBuilder. Class FileStream which exposes a Stream around a file, supporting both synchronous and asynchronous read and write operations. Class StreamWriter which implements a TextWriter for writing characters to a stream in a particular encoding.

We use the btn_Generate_Click and two customed functons fo Stream2Stream,GetFileStream to excute the task. The detailed code as following:

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

The flow for the code behind page is as follows

Download Source Files