void fileUpload_FileUploadCompleted(object sender, FileUploadCompletedEventArgs args) { string id = ctx.Request.QueryString["id"]; //FileInfo fi = new FileInfo(args.FilePath); //string targetFile = Path.Combine(fi.Directory.FullName, args.FileName); //if (File.Exists(targetFile)) // File.Delete(targetFile); //fi.MoveTo(targetFile); }
public void ProcessRequest(HttpContext context, string uploadPath) { string filename = context.Request.QueryString["filename"]; bool complete = string.IsNullOrEmpty(context.Request.QueryString["Complete"]) ? true : bool.Parse(context.Request.QueryString["Complete"]); bool getBytes = string.IsNullOrEmpty(context.Request.QueryString["GetBytes"]) ? false : bool.Parse(context.Request.QueryString["GetBytes"]); long startByte = string.IsNullOrEmpty(context.Request.QueryString["StartByte"]) ? 0 : long.Parse(context.Request.QueryString["StartByte"]); ; string filePath; if (UniqueUserUpload) { if (context.User.Identity.IsAuthenticated) { filePath = Path.Combine(uploadPath, string.Format("{0}_{1}", context.User.Identity.Name.Replace("\\",""), filename)); } else { if (context.Session["fileUploadUser"] == null) context.Session["fileUploadUser"] = Guid.NewGuid(); filePath = Path.Combine(uploadPath, string.Format("{0}_{1}", context.Session["fileUploadUser"], filename)); } } else filePath = Path.Combine(uploadPath, filename); if (getBytes) { FileInfo fi = new FileInfo(filePath); if (!fi.Exists) context.Response.Write("0"); else context.Response.Write(fi.Length.ToString()); context.Response.Flush(); return; } else { if (startByte > 0 && File.Exists(filePath)) { using (FileStream fs = File.Open(filePath, FileMode.Append)) { SaveFile(context.Request.InputStream, fs); fs.Close(); } } else { using (FileStream fs = File.Create(filePath)) { SaveFile(context.Request.InputStream, fs); fs.Close(); } } if (complete) { if (FileUploadCompleted != null) { FileUploadCompletedEventArgs args = new FileUploadCompletedEventArgs(filename, filePath); FileUploadCompleted(this, args); } } } }
public void ProcessRequest(HttpContext context, string uploadPath) { string filename = context.Request.QueryString["filename"]; bool complete = string.IsNullOrEmpty(context.Request.QueryString["Complete"]) ? true : bool.Parse(context.Request.QueryString["Complete"]); bool getBytes = string.IsNullOrEmpty(context.Request.QueryString["GetBytes"]) ? false : bool.Parse(context.Request.QueryString["GetBytes"]); long startByte = string.IsNullOrEmpty(context.Request.QueryString["StartByte"]) ? 0 : long.Parse(context.Request.QueryString["StartByte"]);; string filePath; if (UniqueUserUpload) { if (context.User.Identity.IsAuthenticated) { filePath = Path.Combine(uploadPath, string.Format("{0}_{1}", context.User.Identity.Name.Replace("\\", ""), filename)); } else { if (context.Session["fileUploadUser"] == null) { context.Session["fileUploadUser"] = Guid.NewGuid(); } filePath = Path.Combine(uploadPath, string.Format("{0}_{1}", context.Session["fileUploadUser"], filename)); } } else { filePath = Path.Combine(uploadPath, filename); } if (getBytes) { FileInfo fi = new FileInfo(filePath); if (!fi.Exists) { context.Response.Write("0"); } else { context.Response.Write(fi.Length.ToString()); } context.Response.Flush(); return; } else { if (startByte > 0 && File.Exists(filePath)) { using (FileStream fs = File.Open(filePath, FileMode.Append)) { SaveFile(context.Request.InputStream, fs); fs.Close(); } } else { using (FileStream fs = File.Create(filePath)) { SaveFile(context.Request.InputStream, fs); fs.Close(); } } if (complete) { if (FileUploadCompleted != null) { FileUploadCompletedEventArgs args = new FileUploadCompletedEventArgs(filename, filePath); FileUploadCompleted(this, args); } } } }