<%@ WebHandler Language="C#" Class="FileHandler" %>
using System;
using System.Web;
using System.IO;
public class FileHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
try
{
if (context.Request.Files.Count > 0)
{
HttpPostedFile file =context.Request.Files[0];
file.SaveAs(context.Server.MapPath("upload/"+Guid.NewGuid()+Path.GetExtension(file.FileName)));
context.Response.Write("上传成功!");
}
else
{
context.Response.Redirect("FileUpload.html");
}
}
catch(Exception ex)
{
context.Response.Write(ex.Message);
}
}
public bool IsReusable {
get {
return false;
}
}
}