/*
Tofu is made of excellent products
Http://www.asp888.net bean curd technology station
Retain the copyright information if reprinted.
*/
Many people may have used the ase output by chinaAsp to perform various operations on files on the server. Here we also come
I will talk about a program to implement ase in asp plus. Due to the rush of time and originally for demonstration purpose, this program only demonstrates the simplest situation. As for uploading and editing text files have already been mentioned in, you can go to http://www.asp888.net to view the article in the technical Column
First, list the drive letters on the machine.
<% @ Page Language = "C #" %>
<% @ Import Namespace = "System. IO" %>
<%
String [] LocalDriver = Directory. GetLogicalDrives ();
Int intNum = LocalDriver. Length;
Response. Write ("<ul> ");
For (int I = 0; I <intNum; I ++)
{
%>
<Li> <a href = "dir. aspx? Dir = <% = Server. UrlEncode (LocalDriver [I]) %> "> <% = LocalDriver [I] %> </a> </li>
<%
}
Response. Write ("</ul> ");
%>
List the directories on the selected drive letter
<% @ Page Language = "C #" %>
<% @ Import Namespace = "System. IO" %>
<%
String strDir2List = Server. UrlDecode (Request. QueryString. Get ("dir "));
Directory thisOne = null;
Try
{
ThisOne = new Directory (strDir2List );
// Obtain the Current Directory Creation Time
Response. Write ("<p> Current Directory:" + thisOne. ToString () + "</p> ");
Directory [] Dir = thisOne. GetDirectories ();
Response. Write ("<ul> ");
For (int I = 0; I <Dir. Length; I ++)
{
Response. Write ("<li> <a href =" dir. aspx? Dir = ");
Response. Write (Server. UrlEncode (Dir [I]. FullName ));
Response. Write (""> "+ Dir [I]. Name );
Response. Write ("</a> <br> ");
}
Response. Write ("</ul> ");
File [] Files = thisOne. GetFiles ();
Response. Write ("<ul> ");
For (int I = 0; I <Files. Length; I ++)
{
Response. Write ("<li> <a href =" viewfile. aspx? File = ");
Response. Write (Server. UrlEncode (Files [I]. FullName ));
Response. Write (""> "+ Files [I]. Name );
Response. Write ("</a> <br> ");
}
Response. Write ("</ul> ");
}
Catch (Exception e)
{
Response. Write ("error: <I> ");
Response. Write (e. ToString () + "</I> ");
Response. End ();
}
%>
View the file details:
<% @ Page Language = VB %>
<% @ Import Namespace = "System" %>
<% @ Import Namespace = "System. IO" %>
<Html>
<Head> <title> edit file </title> <Body>
<%
Dim File as string
File = Request. QueryString. Get ("file ")
ThisOne = new File (File)
String File = Request. QueryString. Get ("file ");
File thisOne = new File (File );
%>
<Table>
<Tr> <td> file Name: </td> <% = thisOne. Name %> </td> </tr>
<Tr> <td> full name of the file: </td> <% = thisOne. FullName %> </td> </tr>
<Tr> <td> directory: </td> <% = thisOne. DirectoryName %> </td> </tr>
<Tr> <td> File Creation Time: </td> <% = thisOne. CreationTime. ToString () %> </td> </tr>
<Tr> <td> file size: </td> <% = thisOne. Length. ToString () %> Bytes </td> </tr>
<Tr> <td> last access time: </td> <% = thisOne. LastAccessTime. ToString () %> </td> </tr>
<Tr> <td> Last Update Time: </td> <% = thisOne. LastWriteTime. ToString () %> </td> </tr>
</Table>
<%
Ss = split (thisOne. Name ,".")
Fileent = lcase (ss (ubound (ss )))
If fileent = "txt" or fileent = "asp" or fileent = "aspx" then
TheReader = thisOne. OpenText ()
Do
StrIn = theReader. ReadLine ()
Response. write (strIn)
Loop Until strIn = Null
%>
<Form action = "savefile. asp" method = post>
<Textarea cols = 40 rows = 30> <% = strIn %> </textarea>
<Input type = hidden name = filename value = "<% = thisOne. FullName %>">
<Br>
<Input type = submit value = "Save changes">
</Form>
<%
End if
%>
</Body>
</Html>
Well, a complete ase program also needs to delete, copy, move, and upload and edit files. I believe that after reading this program, you will surely find a way to implement it through simple changes.
The complete example of this program can be downloaded in http://www.asp888.net/download/asp/ase.zip
Thank you!
Author: tofu ()