asp.net
Examples of manipulating files in asp.net
1, write the document
Writefile.aspx
<%@ Import namespace= "System.IO"%> ' introduced the required Namespace
<%
Response.Write ("Writing the content into Text File in asp.net <BR>")
Dim Strwriterobj as StreamWriter ' declares a StreamWriter object
strwriterobj= file.createtext ("c:\aspnet.txt") ' Create a new text file, assign to StreamWriter object
Strwriterobj. WriteLine ("Welcome to wonderfull world of asp.net programming")
' Write content to a file
Strwriterobj. Close ' Closes the object
Response.Write ("Done with the creation of text file and writing content into it")
%>
2, read the file
Readfile.aspx
<%@ Import namespace= "System.IO"%>
<%
Response.Write ("Reading" the content from the text file ASPNET.) TXT <br> ")
Dim streamreaderobj as StreamReader ' declares a StreamReader object
Dim Filecont as String ' declares a variable to save read-out content
Streamreaderobj = File.OpenText ("c:\aspnet.txt") ' Open file assignment to StreamReader object
Do ' reads the contents of a file by line
Filecont = Streamreaderobj. ReadLine ()
Response.Write (Filecont & "<br>")
Loop Until Filecont = ""
Streamreaderobj. Close ' Closes the StreamReader object
Response.Write ("<br> done with reading the content from the file Aspnet.txt")
%>
3, delete the file
Filedelete.aspx
<%@ Import namespace= "System.IO"%>
<%
File.delete ("C:\aspnet.txt") ' Delete file
Response.Write ("The File ASPNET is deleted successfully!!!")
%>