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.

    Regards, I value it.
    cialis chennai
    buy cialis online
    is cialis used for bph
    cialis generic

  2. Your comment is awaiting moderation.

  3. Your comment is awaiting moderation.

    Many thanks, Great stuff!
    para comprar cialis necesito receta medica en mexico cialis generic cialis one a day side effects cialis online
    cialis bande mou
    precios cialis levitra
    cialis echt of nep
    precio del cialis en andorra
    cialis generico opinioni
    cialis mua o dau

Leave a Reply

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