/*
豆腐制作 都是精品
http://www.asp888.net 豆腐技术站
如转载 请保留版权信息
*/
很多人可能都用过 chinaAsp 出的 ase 可以对 服务器上的文件进行各种操作,在这里我们也来
讲一个在 asp plus 下实现 ase 的程序 由于时间仓促 和本来就是 出于 演示的目的 本程序只演示了最简单的 情况 至于 上传 和编辑文本文件 我在 以前的文章里 都已经 讲过了,大家可以到 http://www.asp888.net 查看技术栏目里面的文章
首先是 列出 机器上 的盘符
1 @Page Language="C#"
1 @Import Namespace="System.IO"
1
2string[] LocalDriver = Directory.GetLogicalDrives();
3int intNum = LocalDriver.Length;
4Response.Write("
<ul>");
for (int i=0; i < intNum; i++)
{
1<li><a href="dir.aspx?dir=```
2=Server.UrlEncode(LocalDriver[i])
3```">```
4=LocalDriver[i]
5```</a></li>
}
Response.Write("</ul>
1");
列出所选择的盘符 上的目录
1 @Page Language="C#"
1 @Import Namespace="System.IO"
1
2string strDir2List = Server.UrlDecode(Request.QueryString.Get("dir"));
3Directory thisOne = null;
4try
5{
6thisOne = new Directory(strDir2List);
7// 得到当前的目录创建时间
8Response.Write("
<p>当前所在目录: " + thisOne.ToString() + "</p>
1");
2Directory[] Dir = thisOne.GetDirectories();
3Response.Write("
<ul>");
for (int i=0; i < Dir.Length; i++)
{
Response.Write("<li><a href='"dir.aspx?dir=");' response.write(""="" response.write(server.urlencode(dir[i].fullname));="">" + Dir[i].Name);
Response.Write("</a><br/>");
}
Response.Write("</li></ul>
1");
2
3File[] Files = thisOne.GetFiles();
4Response.Write("
<ul>");
for (int i=0; i < Files.Length; i++)
{
Response.Write("<li><a href='"viewfile.aspx?file=");' response.write(""="" response.write(server.urlencode(files[i].fullname));="">" + Files[i].Name);
Response.Write("</a><br/>");
}
Response.Write("</li></ul>
1");
2}
3catch (Exception e)
4{
5Response.Write("错误:
<i>");
Response.Write(e.ToString() + "</i>
1");
2Response.End();
3}
查看文件的详细信息:
1 @Page Language=VB
1 @Import Namespace="System"
1 @Import Namespace="System.IO"
1<html>
2<head><title>编辑文件</title></head>
3<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);
1<table>
2<tr><td>文件名称:</td><td>```
3=thisOne.Name
4```</td></tr>
5<tr><td>文件的全名:</td><td>```
6=thisOne.FullName
7```</td></tr>
8<tr><td>所在目录:</td><td>```
9=thisOne.DirectoryName
10```</td></tr>
11<tr><td>文件创建时间:</td><td>```
12=thisOne.CreationTime.ToString()
13```</td></tr>
14<tr><td>文件大小:</td><td>```
15=thisOne.Length.ToString()
16``` Bytes</td></tr>
17<tr><td>最近一次的存取时间:</td><td>```
18=thisOne.LastAccessTime.ToString()
19```</td></tr>
20<tr><td>最近一次更新时间:</td><td>```
21=thisOne.LastWriteTime.ToString()
22```</td></tr>
23</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
1<form action="savefile.asp" method="post">
2<textarea cols="40" rows="30">```
3=strIn
4```</textarea>
5<input name="filename" type="hidden" value="```
6=thisOne.FullName
7```"/>
8<br/>
9<input type="submit" value="保存更改"/>
10</form>
end if
1</body>
2</html>
好了一个完整的 ase 程序还需要 删除 拷贝 移动和上传 编辑 相信大家在 看完这个程序以后 一定会 有办法 经过 简单 的改动 就 可以实现
这个程序的完整例子可以在 http://www.asp888.net/download/asp/ase.zip 下载
谢谢大家
作者:豆腐()