<%@ WebHandler Language="C#" Class="Handler" %> using System; using System.Web; using System.Web.Script.Serialization; using System.IO; public class Handler : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "application/json; charset=utf-8"; //"text/plain"; context.Response.Expires = -1; var r = new System.Collections.Generic.List(); JavaScriptSerializer js = new JavaScriptSerializer(); foreach (string file in context.Request.Files) { HttpPostedFile hpf = context.Request.Files[file] as HttpPostedFile; string FileName = string.Empty; if (HttpContext.Current.Request.Browser.Browser.ToUpper() == "IE") { string[] files = hpf.FileName.Split(new char[] { '\\' }); FileName = files[files.Length - 1]; } else { FileName = hpf.FileName; } if (hpf.ContentLength == 0) continue; string savedFileName = context.Server.MapPath("~/Files/" + FileName); hpf.SaveAs(savedFileName); r.Add(new ViewDataUploadFilesResult() { thumbnail_url = savedFileName, //context.Server.MapPath("~/Files/" + FileName), //savedFileName, url = savedFileName, //context.Server.MapPath("~/Files/" + FileName), name = FileName, size = hpf.ContentLength, type = hpf.ContentType }); var uploadedFiles = new { files = r.ToArray() }; var jsonObj = js.Serialize(uploadedFiles); //jsonObj.ContentEncoding = System.Text.Encoding.UTF8; //jsonObj.ContentType = "application/json;"; context.Response.Write(jsonObj.ToString()); } } public bool IsReusable { get { return false; } } } public class ViewDataUploadFilesResult { public string thumbnail_url { get; set; } public string name { get; set; } public int size { get; set; } public string type { get; set; } public string url { get; set; } }