FileUploadProcessResult fileUpload_FileUploadCompleted(object sender, FileUploadCompletedEventArgs args) { var result = new FileUploadProcessResult(); try { result = ProcessUploadedFile(sender, args); } catch (Exception ex) { result.Status = Newegg.Oversea.Silverlight.FileUploadHandler.ProcessStatus.Failed; result.ResponseMsg = ex.ToString(); if (File.Exists(args.FilePath)) { File.Delete(args.FilePath); } } return(result); }
public void ProcessRequest(HttpContext context, string uploadPath) { if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } context.RewritePath(context.Server.UrlDecode(context.Request.Url.PathAndQuery)); string filename = context.Request.QueryString["Filename"]; string clientFileName = filename; string guid = context.Request.QueryString["Guid"]; string uploadParam = context.Request.QueryString["Param"]; var index = filename.LastIndexOf("."); var suffix = filename.Substring(index); 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"]);; if (startByte == 0) { guid = Guid.NewGuid().ToString(); } filename = guid + suffix; string filePath = Path.Combine(uploadPath, filename); if (startByte > 0 && File.Exists(filePath)) { using (FileStream fs = File.Open(filePath, FileMode.Append)) { SaveFile(context.Request.InputStream, fs); } } else { using (FileStream fs = File.Create(filePath)) { SaveFile(context.Request.InputStream, fs); } } FileUploadProcessResult processResult = new FileUploadProcessResult(); if (complete) { if (FileUploadCompleted != null) { FileUploadCompletedEventArgs args = new FileUploadCompletedEventArgs(clientFileName, filename, filePath, uploadParam); processResult = FileUploadCompleted(this, args); } else { processResult.Status = ProcessStatus.Success; } if (DeleteFileAfterUpload) { if (File.Exists(filePath)) { File.Delete(filePath); } } } var responseString = string.Format("NeweggFileUploaderResponse[^v^]{0}[^v^]{1}[^v^]{2}[^v^]{3}", guid, context.Request.InputStream.Length, processResult.ResponseMsg, processResult.Status); context.Response.Write(responseString); context.Response.Flush(); }
public abstract FileUploadProcessResult ProcessUploadedFile(object sender, FileUploadCompletedEventArgs args);