Creating a File (VB) : File « File Directory « ASP.NET Tutorial






<%@ Page Language="vb" Explicit="true" Strict="true" %>
<%@ Import Namespace = "System.IO" %>
<script language="vb" runat="Server">
    Sub CreateFile(sender As Object, e As EventArgs)
        If Trim(TextContent.Text).Length > 0 Then
            Dim myFileStream As StreamWriter = Nothing
            Try
                myFileStream = File.CreateText(Server.MapPath(".\Upload\") & "test.txt")
                myFileStream.WriteLine(TextContent.Text)
                myFileStream.Close()
                Output.Text = "File Successfully Created!"
            Catch exc As Exception
                Output.Text = "Error in Creating file. Error is " & exc.ToString()
            Finally
        If Not myFileStream Is Nothing Then
          myFileStream.Close()
        End If
            End Try
        Else
            Output.Text = "File not created, because you didn't enter anything!"
        End If
    End Sub
</script>
<HTML>
  <HEAD>
    <title>Creating a File</title>
  </HEAD>
  <body>
    <form id="Form1" method="post" runat="server">
      <asp:Label ID="Msg" Runat="server" Text="Please enter some text: "></asp:Label><br>
      <asp:TextBox ID="TextContent" Runat="server" TextMode="MultiLine" Rows="10" Columns="75"></asp:TextBox><br>
      <asp:Button ID="Submit" Runat="server" Text="Submit" OnClick="CreateFile"></asp:Button>
      <asp:Label ID="Output" Runat="server"></asp:Label>
    </form>
  </body>
</HTML>








10.1.File
10.1.1.Get file information (VB.net)
10.1.2.Opening a File (C#)
10.1.3.Opening a File (VB)
10.1.4.Delete a file (C#)
10.1.5.Delete a file (VB)
10.1.6.Creating a File (C#)
10.1.7.Creating a File (VB)
10.1.8.Load file content to DropDownList (C#)
10.1.9.Load file content to DropDownList (VB)
10.1.10.Rename File