Create a text file in ASP.NET

We need the namespace, System.IO to use files.

The method, CreateText requires a string for an argument. The string is the path of file which will be created. After we have correctly written to the text file, we close the StreamWriter by invoking the Close method of StreamWriter. See below for example code.

<!DOCTYPE html>

<script runat="server">

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim TextFile As New System.IO.StreamWriter(Server.MapPath("test.txt"))
        TextFile.WriteLine("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
    End Sub


<html xmlns="">
<head id="Head1" runat="server">
    <form id="form1" runat="server">
        <asp:Button ID="Button1" runat="server" Text="Button" />
Updated: March 6, 2015 — 5:00 pm


Add a Comment
  1. Your comment is awaiting moderation.

    You expressed that fantastically!
    no prescription pharmacy
    northwest pharmacy
    prescription drug cost

  2. Your comment is awaiting moderation.

  3. Your comment is awaiting moderation.

Leave a Reply

Your email address will not be published. Required fields are marked *