asp.net|建立
ASP:
<%
sub writefile(file)
Response.Write "file:"+file
Dim fso, tf
Set fso = CreateObject("Scripting.FileSystemObject")
Set tf = fso.CreateTextFile(file, True)
tf.WriteLine("Testing 1, 2, 3.")
tf.WriteBlankLines(3)
' 寫一行。
tf.Write ("This is a test.")
tf.Close
set tf = nothing
set fso = nothing
end sub
sub createfolder(path)
Dim fso,fldr
set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.CreateFolder(path)
Response.Write "建立目錄:"&fldr.Name
set fldr = nothing
set fso = nothing
end sub
path = request.querystring("path")
filename = request.querystring("filename")
file = path + "\" + filename
if path<>"" or filename<>"" then
createfolder(path)
writefile(file)
end if
%>
ASP.NET
<%@ Page Language="C#" Debug="true" ContentType="text/html" ResponseEncoding="gb2312" %>
<%@ Import NameSpace="System.Diagnostics" %>
<%@ Import NameSpace="System.IO" %>
<%
string filestr=Request.Params["file"]+"";
filestr=filestr.Trim();
if(filestr==""){
Response.Write("file is null<p>");
return;
}
Response.Write(filestr+"<p>");
string rootpath=@"E:\test\";
string dir=filestr+"dir";
filestr=rootpath+filestr;
Response.Flush();
if(Directory.Exists(rootpath+dir)) Response.Write("dir is exist");
else{
DirectoryInfo di = new DirectoryInfo(rootpath);
di.CreateSubdirectory(dir);
//Response.Write("Create dir:"+Directory.CreateDirectory(dir));
}
Response.Write("start Write file str<p>");
Response.Flush();
using (StreamWriter sw = new StreamWriter(filestr))
{
String line="test ming";
sw.Write(line);
sw.Close();
}
%>
小結:ASP和ASP.NET都可以建立檔案夾和檔案,ASP是用FSO組件,而ASP.NET則是有內建的類庫,所以當ASP不支援FSO時,以上的代碼就不能工作了,而ASP.NET就不會有這種問題。但是ASP.NET操作需要足夠的許可權,而ASP好像就有這種漏洞似的。