How to operate file in ASP.NET
Author: Wawe Time: 2002-9-28 Recommended Level: ★ View author information and author anthology
Author: chenyangasp in all operating concept asp.net files are system.io namespace, this namespace contains the file read and write operations required for the class. This article will detail the file operations in ASP.NET, such as file read, write, delete, etc. Create a file: and write some content. Just as starting we mentioned, we need to add files "system.io" in front of our ASP.NET's page: Add Namespace <% @ Import Namespace = "System.io" by adding Namespace <% @ import name > Next Making text file Writefile.aspx <% @ import namespace = "system.io"%> <% response.write ("Writing the content inTo text file in asp.write (" Writing the content inTo text file in asp.Net
")" Declaration Streamwriter object DIM STRWRITEROBJ AS streamwriter creates a text file and assigns it to the Streamwriter object Strwriterobj = file.cretetext ("C: /ASPNET.TXT") "written in the text file created," Welcome To " User Chenyang "S ASP.NET Program" StrWriterobj.close Response.write ("Create text file and populate content")%> Now we have completed the first part, then let's complete the second part to read data from the file 1. Read the file Using the StreamReader class 2. When using readline, the end of the file is indicated by an empty string ("") Let us read the data readfile.aspx <% @ Import Namespace = "System from the text file we just produced. .Io "%> <% response.write (" Reading The Content from the Text File ASPNET.TXT
")" Declaration StreamReader Object DIM StreamReaderobj As StreamReader "Declares Data Data Data Data Data DIM FileCont AS String "Open text file and assume StreamReaderobj object streamreaderobj = file.opentext (" c: /ASPNET.TXT ")" read file data until nullcont = streamreaderobj.readline () Response.write (FileCont & " ") loop unsil filecont =" "" Operation completes the StreamReaderobj object streamReaderobj.closeSponse.write ("
Read the ASPNET.TXT File End")%> Three Delete File Delete File Operation can be said in ASP.NET It is most direct.