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.")
        TextFile.Close()
    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
    </form>
</body>
</html>
Updated: March 6, 2015 — 5:00 pm

Comments

Add a Comment
  1. Your comment is awaiting moderation.

    Regards, I value it.
    http://cialispego.com/
    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!
    http://cialispego.com/
    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 *