ASP Programming Entry Advanced (3): FSO Component file operation (ON)

Source: Internet
Author: User

Learned the FSO to extract the file value, but also learned to input the information into the file, then the following application.

Do not know you have no such habit: see a file, the unconscious right to choose to open Notepad. Oh, almost no document is not possible. So now, you can default all files are text, but the suffix name is different, so that is, you can now extract the contents of any file information. OK, Just imagine:

1, extract the path of a file (using the file button to find positioning)

2, open the path file and read all rows

3, displaying the read information

First, viewcode.asp

<%
Function ShowCode(filename)
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set cnrs = fso.OpenTextFile(filename, 1)
While Not cnrs.AtEndOfStream
rsline = cnrs.ReadLine
rsline = server.HTMLEncode(rsline)
Response.Write(rsline & "<br>")
Wend
end Function
%>
<form action="viewcode.asp" method="post">
输入文件名<input type="file" name="filename">
<input type="submit" value="查看源程序">
</form>
<%
file=request.form("filename")
response.write (file & "源程序如下 If trim(file)<> "" then
Call ShowCode(file)
End If
%>

The above program debugging, you can choose Html,asp page, you can open any application and so on.

The ShowCode function is defined to open, read, and display all the contents of the information in the file. Note the server is added. HTMLEncode (Rsline) for files that contain standard HTML code.

Displaying all the rows in a file is displayed by looping through a conditional loop.

While not CNRS. AtEndOfStream

...

Wend

Next, the following example specifically covers the question of the open method, remember? Under normal circumstances, open the file is to use the FSO. OpenTextFile ("C:\testfile.txt", 1), and the function of parameter 1 is to open the file in read-only mode. This file cannot be written to. What if a file already exists and an append write is required? Simple, the parameter is 8.

What's the use? Oh, Amazon's network story solitaire is so: can Solitaire need to first show the original story, and then add their own stories to write files. One of the most exquisite writing files is the append write. So the following can be achieved.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.