使用ASP和ASP.NET来创建文件夹和文件。

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好像就有这种漏洞似的。   

时间: 2024-08-04 00:46:20

使用ASP和ASP.NET来创建文件夹和文件。的相关文章

Asp.net对文件夹和文件的操作类

asp.net using System;using System.IO;using System.Web; namespace SEC{    /**//// <summary>    /// 对文件和文件夹的操作类    /// </summary>    public class FileControl    {        public FileControl()        {                    }        /**//// <summa

asp.net 检查文件夹和文件是否存在

允许 path 参数指定相对或绝对路径信息. 相对路径信息被解释为相对于当前工作目录. 检查该目录是否存在之前,从 path 参数的末尾移除尾随空格. path 参数不区分大小写. 如果您没有该目录的最小只读权限,exists 方法将返回 false. if directory.exists(path) then                     ' this path is a directory.                     processdirectory(path)  

asp.net C#文件操作(追加、拷贝、删除、移动文件、创建目录、递归删除文件夹及文件)

asp教程.net c#文件操作(追加.拷贝.删除.移动文件.创建目录.递归删除文件夹及文件) c#追加.拷贝.删除.移动文件.创建目录.递归删除文件夹及文件.指定文件夹下 面的所有内容copy到目标文件夹下面.指定文件夹下面的所有内容detele.读取文本文件.获取文件列表.读取日志文件.写入日志文件.创建html 文件.createdirectory方法的使用 c#追加文件 streamwriter sw = file.appendtext(server.mappath(".")+

asp.net遍历文件夹所有文件并列出代码

asp教程.net遍历文件夹所有文件并列出代码 下面的代码是一款c# asp.net教程的文件夹里面的所有文件列出来哦,并且显示了文件创建时间,文件名哦. directoryinfo di;   fileinfo[] filelist;   datagridview dgvlist;   datatable dtable = new datatable();   dtable.columns.add("filename");   dtable.columns.add("cre

Asp.net获取服务器指定文件夹目录文件并提供下载的方法

 这篇文章主要介绍了Asp.net获取服务器指定文件夹目录文件并提供下载的方法,涉及使用http协议操作文件的技巧,需要的朋友可以参考下 本文实例讲述了Asp.net获取服务器指定文件夹目录文件并提供下载的方法.分享给大家供大家参考.具体实现方法如下: 代码如下: string dirPath = HttpContext.Current.Server.MapPath("uploads/"); if (Directory.Exists(dirPath)) { //获得目录信息 Direc

在ASP.NET的页面中显示FTP中的文件夹和文件信息

问题描述 那位兄弟,在ASP.NET做过这种效果,连接FTP并把FTP上的第一层的文件夹或文件显示在ASP.NET的页面上,然后单击文件夹,就在页面上显示你选中的这个文件夹里面一层的文件夹或文件信息,单击文件的话就直接打开文件,还能返回上层文件夹的功能.最好还能过滤文件的类型.我对FTP不是很了解,无法下手.那位可以给点建议.谢了. 解决方案 解决方案二:参考http://blog.csdn.net/downmoon/archive/2008/01/29/2071776.aspxhttp://w

asp.net编程实现删除文件夹及文件夹下文件的方法_实用技巧

本文实例讲述了asp.net编程实现删除文件夹及文件夹下文件的方法.分享给大家供大家参考,具体如下: //获取文件夹 string path = Server.MapPath("Image"); //获取文件夹中所有图片 if (Directory.GetFileSystemEntries(path).Length > 0) { //遍历文件夹中所有文件 foreach (string file in Directory.GetFiles(path)) { //文件己存在 if

用asp实现的获取文件夹中文件的个数的代码_应用技巧

复制代码 代码如下: '返回指定文件夹中文件的数目,传入值为被检测文件夹的硬盘绝对路径 function CountFilesNumber(folderspec) Dim objfso,f,fc Set objfso=CreateObject("Scripting.FileSystemObject") Set f=objfso.GetFolder(folderspec) Set fc=f.Files CountFilesNumber=fc.Count set fc=nothing se

用asp实现的获取文件夹中文件的个数的代码

复制代码 代码如下: '返回指定文件夹中文件的数目,传入值为被检测文件夹的硬盘绝对路径 function CountFilesNumber(folderspec) Dim objfso,f,fc Set objfso=CreateObject("Scripting.FileSystemObject") Set f=objfso.GetFolder(folderspec) Set fc=f.Files CountFilesNumber=fc.Count set fc=nothing se