public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Charset = "utf-8"; HttpPostedFile file = context.Request.Files["Filedata"]; string uploadPath = context.Server.MapPath("~/UpLoadFiles/IGU/"); string FileParentID = context.Request["ParentID"].Replace("'", ""); if (file != null) { FileID = Guid.NewGuid().ToString(); string FileType = file.FileName.Substring(file.FileName.LastIndexOf('.') + 1).ToLower(); string FileName = file.FileName.Substring(0, file.FileName.LastIndexOf('.')); string filePath = DateTime.Now.ToString("yyyyMMdd") + "/"; uploadPath += filePath; if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } uploadPath += FileID + "." + FileType; filePath += FileID + "." + FileType; file.SaveAs(uploadPath); SDMS_IGU model = new SDMS_IGU(); model.ID = new Guid(FileID); model.IGUID = new Guid(FileParentID); model.ImagePath = filePath; model.CreatedDate = DateTime.Now; model.ImagePath_Name = filePath.Substring(0, filePath.LastIndexOf('.')); model.ImagePath_Type = "." + FileType; db.SDMS_IGU.Add(model); db.SaveChanges(); MemoryStreamSmall(file, uploadPath, FileType, 120, 120); FileID = "/UpLoadFiles/IGU/" + model.ImagePath_Name + "A" + model.ImagePath_Type; } context.Response.Write(FileID); }