using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; namespace WWPipeLine.MapWebTools.Tools { /// /// PictureUpload 的摘要说明 /// public class PictureUpload : IHttpHandler { private static string imgUploadDir = System.Configuration.ConfigurationManager.ConnectionStrings["imgUploadDir"].ConnectionString; private static string GISversion = System.Configuration.ConfigurationManager.ConnectionStrings["GISversion"].ConnectionString; public void ProcessRequest(HttpContext context) { //context.Response.ContentType = "text/plain"; //context.Response.Write("Hello World"); string action = context.Request.QueryString["action"]; switch (action) { case "UpLoadFile": UpLoadFile(context); break; case "getGISversion": { context.Response.Write(GISversion); context.Response.End(); } break; default: UpLoadFile(context); break; } } private void UpLoadFile(HttpContext context) { try { string fileName = context.Request.QueryString["name"]; if (string.IsNullOrEmpty(fileName)) { context.Response.Write(""); context.Response.End(); return; } string imgMapPath = context.Server.MapPath(imgUploadDir); if (!Directory.Exists(imgMapPath)) Directory.CreateDirectory(imgMapPath); foreach (string f in context.Request.Files.AllKeys) { HttpPostedFile httpPostedFile = context.Request.Files[f]; httpPostedFile.SaveAs(imgMapPath + fileName); } context.Response.Write(imgUploadDir + fileName); } catch (Exception ex) { context.Response.Write(""); } finally { context.Response.End(); } } public bool IsReusable { get { return false; } } } }