ASP.NET how to operate files

xiaoxiao2021-03-06  125

This article is copyrighted by chenyangasp, reproduced, copy, paste, and please indicate the source, but you must not modify!

All Concepts in the ASP.NET Operating file are in System.io Namespace, which contains the classes necessary to read and write operations files.

This article will detail the file operations in ASP.NET, such as file read, write, delete, etc.

Create a file: and write some content.

As started to mention, we need to add file operations in front of our ASP.NET's page. "System.io"

first step:

Add Namespace as shown below

<% @ Import namespace = "system.io"%>

Next step production text file

Writefile.aspx

<% @ Import namespace = "system.io"%>

<%

Response.write ("Writing The Content Into Text File in Asp.Net
)

"Statement Streamwriter object

DIM STRWRITEROBJ AS streamwriter

"Create a text file and assign it to the StreamWriter object that is declared above.

Strwriterobj = file.createtext ("c: /ASPNET.TXT")

"Writing some Dongdong in the text file created in just now

Strwriterobj.writeline ("Welcome to User Chenyang" S asp.net program ")

Strwriterobj.close

Response.write ("Create text files and fill content")

%>

Now we have completed the first part

Next, let's complete the second part

Read data from the file

1. Read files to use StreamReader class

2. When using readline, use an empty string to expand ("") at the end of the file.

Let us read data from our text files we have just made

Now let "s Go

Readfile.aspx

<% @ Import namespace = "system.io"%>

<%

Response.write ("Reading The Content from the Text File ASPNET.TXT
")

"Statement StreamReader object

Dim StreamReaderobj As StreamReader

"Declare the data read in the FileCont variable storage file

Dim FileCont As String

"Open text files and assume StreamReaderobj objects

StreamReaderobj = file.opentext ("c: /Aspnet.txt")

"Read file data until null value

DO

FileCont = streamreaderobj.readline ()

Response.write (FileCont & "
)

Loop unsil filecont = "" "

"Operation completes the StreamReaderobj object

StreamReaderobj.Close

Response.write ("
reading the ASPNET.TXT file end")

%>

Three delete files

The operation of the deleted file can be said to be the most direct in ASP.NET. Let's take a look at the deletion of the file.

FILEDELETE.ASPX

<% @ Import namespace = "system.io"%>

<%

File.delete ("c: /Aspnet.txt")

Response.write ("file delete success !!!")

%>

转载请注明原文地址:https://www.9cbs.com/read-100073.html

New Post(0)