<%@ WebHandler Language="C#" Class="UploadHandler" %> using System; using System.Web; using System.IO; using System.Drawing; using System.Drawing.Drawing2D; public class UploadHandler : IHttpHandler { public void ProcessRequest (HttpContext context) { //string path = context.Request["path"]; //FileInfo fn = new FileInfo(path); //fn.CopyTo(context.Server.MapPath("Image/"+fn.Name)); //context.Response.Write(fn.Name+":"+fn.Extension); if (context.Request.Files.Count > 0) { HttpFileCollection files = context.Request.Files; for (int i = 0; i < files.Count; i++) { HttpPostedFile file = files[i]; string fname,path,newfname; if (HttpContext.Current.Request.Browser.Browser.ToUpper() == "IE" || HttpContext.Current.Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER") { string[] testfiles = file.FileName.Split(new char[] { '\\' }); fname = testfiles[testfiles.Length - 1]; } else { fname = file.FileName; } Random random = new Random(1000); int r=(new Random()).Next(100, 1000); fname = r + fname; //fname = random.Next(100,1000) + fname; newfname = fname; // fname = Path.Combine(context.Server.MapPath("AgentImage/"), fname); path = Path.Combine(context.Server.MapPath("AgentImage/"), fname); file.SaveAs(path); context.Response.Write("AgentImage/"+fname); } } //context.Response.ContentType = "text/plain"; } public bool IsReusable { get { return false; } } }