How to work file sytem object in asp.net?

serena

New Member
Hi,<BR>I want to create a text file in asp.net page. Can any one help me? plz..You are going to want to look into the System.IO namespace.You can use something like this, for example. Of course, you have to do your own validation.<BR><BR><html><BR><head><BR><title>Create File</title><BR><script language="VB" runat="server"><BR>Sub CreateBtn_Click(Sender As Object, E As EventArgs)<BR> dim filename as string<BR> dim str as string<BR> str = textarea.value<BR> filename = server.mappath("test.txt")<BR> dim fs = server.createobject("Scripting.FileSystemObject")<BR> dim textstream = fs.CreateTextFile(filename, 2)<BR> textstream.WriteLine(str)<BR> textstream.Close<BR>End Sub<BR>Sub ReadBtn_Click(Sender As Object, E As EventArgs)<BR> dim filename as string<BR> dim str as string<BR> filename = server.mappath("test.txt")<BR> dim fs = server.createobject("Scripting.FileSystemObject")<BR> dim textstream = fs.OpenTextFile(filename)<BR> textarea.value = http://aspmessageboard.com/archive/index.php/textstream.ReadAll()<BR> textstream.Close<BR>End Sub<BR></script><BR></head><BR><body><BR><form runat="server"><BR><textarea id="textarea" runat="server" cols="50" rows="8" /><BR><BR><asp:button text="Save File" OnClick="CreateBtn_Click" runat="server" /><BR><asp:button text="Read File" OnClick="ReadBtn_Click" runat="server" /><BR><BR></form><BR></body><BR></html>
 
Back
Top