使用UpFiles.ashx进行文件上传后如何实现文件删除呢?
<%@ WebHandler Language="C#" Class="Uploader" %>
using System;
using System.IO;
using System.Web;
public class Uploader : IHttpHandler
{
public void ProcessRequest(HttpContext hc)
{
foreach (string fileKey in hc.Request.Files)
{
HttpPostedFile file = hc.Request.Files[fileKey];
string strPath = hc.Server.MapPath(".") + "\\updata\\" + DateTime.Now.ToString("yyyy-MM") + "\\";
if (!Directory.Exists(strPath))
{
Directory.CreateDirectory(strPath);
}
file.SaveAs(Path.Combine(strPath, file.FileName));
}
}
public bool IsReusable
{
get { return true; }
}
}
上传可以使用,但是如果发现上传文件错误,想在删除上传文件如何实现?