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.