本文共 611 字,大约阅读时间需要 2 分钟。
public class FileUpload : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; HttpPostedFile f=context.Request.Files[0];//接收浏览器端传递过来的文件。
string filePath = "Files"; if (f.ContentLength > 0)//判断文件的大小 { string fileName= System.IO.Path.GetFileName(f.FileName);//获得具体的文件名称. filePath = context.Server.MapPath(filePath + "/" + fileName);//指定服务端保存文件的路径。(对文件操作一定是物理路径) f.SaveAs(filePath);//将上传的文件保存到指定的目录。 context.Response.Write("文件上传成功"); } } public bool IsReusable { get { return false; } }} 转载于:https://www.cnblogs.com/yuruyi/archive/2012/08/16/2642622.html