/// <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> /// 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> /// 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="defaultProcessor">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); _settings = UploadConfigurationSection.GetConfig(); if (String.IsNullOrEmpty(ImagePath)) { ImagePath = _settings == null ? DEFAULT_IMAGE_PATH : _settings.ImagePath; } ImagePath = ImagePath.TrimEnd('/') + "/"; if (String.IsNullOrEmpty(CSSPath)) { CSSPath = _settings == null ? DEFAULT_CSS_PATH : _settings.CSSPath; } CSSPath = CSSPath.TrimEnd('/') + "/"; if (String.IsNullOrEmpty(ScriptPath)) { ScriptPath = _settings == null ? DEFAULT_JS_PATH : _settings.ScriptPath; } if (String.IsNullOrEmpty(ProgressUrl)) { ProgressUrl = _settings == null ? DEFAULT_PROGRESS_URL : _settings.ProgressUrl; } if (_settings != null) { AllowedFileExtensions = _settings.AllowedFileExtensions; ShowCancelButton = _settings.ShowCancelButton; ShowProgressBar = _settings.ShowProgressBar; EnableManualProcessing = _settings.EnableManualProcessing; } ScriptPath = ScriptPath.TrimEnd('/') + "/"; if (UploadManager.Instance.ModuleInstalled) { _status = UploadManager.Instance.Status; UploadManager.Instance.Status = null; } }