使用ASP和ASP.NET來建立檔案夾和檔案。

來源:互聯網
上載者:User
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好像就有這種漏洞似的。   




相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.