<%@ 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>
|