Example of file operations in ASP. NET
1. Write files
Writefile. aspx
<% @ Import Namespace = "System. IO" %> introduce 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") creates a text File and assigns it to the StreamWriter object.
Strwriterobj. WriteLine ("Welcome to wonderfull world of ASP. NET Programming ")
Write content to a file
Strwriterobj. Close object
Response. write ("Done with the creation of text file and writing content into it ")
%>
2. Read files
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 the read content
Streamreaderobj = File. OpenText ("c: aspnet.txt") open the File and assign the value to the StreamReader object.
Do reads file content cyclically by row
Filecont = streamreaderobj. ReadLine ()
Response. Write (filecont & "<br> ")
Loop Until filecont = ""
Streamreaderobj. Close the StreamReader object
Response. write ("<br> Done with reading the content from the file aspnet.txt ")
%>
3. delete an object
Filedelete. aspx
<% @ Import Namespace = "System. IO" %>
<%
File. Delete ("c: aspnet.txt") Delete a File
Response. write ("The File aspnet is deleted successfully !!! ")
%>