<%@ WebHandler Language="C#" Class="folder" %>
using System;
using System.Web;
using System.IO;
public class folder : IHttpHandler
{
//采用递归的方式遍历,文件夹和子文件中的所有文件。
public void ProcessRequest(HttpContext context)
{
HttpRequest Request = context.Request;
HttpResponse Response = context.Response;
HttpServerUtility Server = context.Server;
//指定输出头和编码
Response.ContentType = "text/html";
Response.Charset = "utf-8";
HttpFileCollection fs = HttpContext.Current.Request.Files;
string newFilePath = Request.Form["sPath"];
if(fs.Count>0)
{
//fs[0]对应FindFile的dirPath就是指定目录,newFilePath绝对赢svrPath就是目标目录,也就是服务器上的目录
FindFile(fs[0].ToString(), newFilePath);
}
Response.Write("<script>parent.FileUploadDeal()</script>");
}
//采用递归的方式遍历,文件夹和子文件中的所有文件。
public void FindFile(string dirPath,string svrPath) //参数dirPath为指定的目录,svrPath是目标目录
{
//目标目录,也就是服务器上的目录
string sFilePath = System.Web.HttpContext.Current.Server.MapPath(svrPath);
//string sFilePath = System.Web.HttpContext.Current.Server.MapPath(Request.Form["svrPath"]);
//创建文件夹
if (!Directory.Exists(sFilePath))
Directory.CreateDirectory(sFilePath);
//在指定目录及子目录下查找文件
DirectoryInfo Dir=new DirectoryInfo(dirPath);
try
{
foreach(DirectoryInfo d in Dir.GetDirectories())//查找子目录
{
FindFile(Dir+d.ToString()+"\\",svrPath+d.ToString()+"\\");
//FindFile(Dir+d.ToString()+"\",svrPath+d.ToString()+"\");
}
foreach(FileInfo f in Dir.GetFiles()) //查找文件
{
//f.SaveAs(Server.MapPath(svrPath + f.ToString()));//如果要保存到其他地方,注意修改这里
f.CopyTo(System.Web.HttpContext.Current.Server.MapPath(svrPath + f.ToString()), true);
HttpContext.Current.Response.Write("4554132");
}
}
catch(Exception e)
{
;
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有