/// <summary> /// Sets the upload status. /// </summary> /// <param name="status">Status to set.</param> /// <param name="key">Upload key.</param> internal void SetStatus(UploadStatus status, string key) { HttpContext.Current.Application[STATUS_KEY + key] = status; }
/// <summary> /// Initialises the upload status which is held as an application /// variable using a unique key. /// </summary> /// <param name="length">The content length.</param> void InitStatus(long length) { _status = new UploadStatus(length); }
/// <summary> /// Processes file uploads through the processor when the upload module is not installed. /// </summary> void ManualProcessUploads() { IFileProcessor processor; processor = _processor == null ? UploadManager.Instance.GetProcessor() : _processor; _status = new UploadStatus(-1); if (processor != null) { ProcessUploadControls(Page.Controls, processor, _status); } }
/// <summary> /// Processes all upload controls in a control collection when the module is not installed. /// </summary> /// <param name="cc">Control collection.</param> /// <param name="proc">The default processor.</param> /// <param name="status">The upload status.</param> void ProcessUploadControls(ControlCollection cc, IFileProcessor defaultProcessor, UploadStatus status) { foreach (Control c in cc) { System.Web.UI.WebControls.FileUpload fu = c as System.Web.UI.WebControls.FileUpload; if (fu != null && fu.HasFile) { IFileProcessor controlProcessor = GetProcessorForControl(fu); IFileProcessor processor = controlProcessor == null ? defaultProcessor : controlProcessor; try { processor.StartNewFile(fu.FileName, fu.PostedFile.ContentType, null, null); processor.Write(fu.FileBytes, 0, fu.FileBytes.Length); processor.EndFile(); status.UploadedFiles.Add(new UploadedFile(fu.FileName, processor.GetIdentifier(), null)); } catch(Exception ex) { status.ErrorFiles.Add(new UploadedFile(fu.FileName, processor.GetIdentifier(), null, ex)); } } if (c.HasControls()) { ProcessUploadControls(c.Controls, defaultProcessor, status); } } }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init"/> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); if (string.IsNullOrEmpty(this.ReferencePath)) { throw new ArgumentNullException("ReferencePath,例如:<FileUploads:DJUploadController ID=\"DJUploadController1\" runat=\"server\" ReferencePath=\"Backend/images/HtmlEditor/Dialogs/InsertPhotos/\" />"); } string applicationPath = System.Web.HttpContext.Current.Request.ApplicationPath.TrimEnd('/'); string referencePath = this.ReferencePath.TrimStart('/').TrimEnd('/'); ImagePath = string.Format("{0}/{1}/Images/", applicationPath, referencePath); CSSPath = string.Format("{0}/{1}/Styles/", applicationPath, referencePath); ScriptPath = string.Format("{0}/{1}/Scripts/", applicationPath, referencePath); ProgressUrl = string.Format("{0}/{1}/UploadProgress.aspx", applicationPath, referencePath); if (UploadManager.Instance.ModuleInstalled) { _status = UploadManager.Instance.Status; UploadManager.Instance.Status = null; } }