Legacy UploadAttachments
UploadAttachments is the compatibility control for form-style attachment lists.
Use it when an older page expects:
- an attachment table UI
- the
Itemscollection AttachmentItemevent hooks- optional custom attachment providers
Typical markup
<%@ Register Assembly="AjaxUploader" Namespace="CuteWebUI" TagPrefix="CuteWebUI" %>
<CuteWebUI:UploadAttachments ID="Attachments1" runat="server"
InsertText="Upload multiple files"
MultipleFilesUpload="true"
ShowQueueTable="true"
ShowTableHeader="true"
ShowRemoveButtons="true"
OnFileUploaded="Attachments1_FileUploaded"
OnAttachmentAdded="Attachments1_AttachmentAdded"
OnAttachmentRemoveClicked="Attachments1_AttachmentRemoveClicked">
<ValidateOption AllowedFileExtensions="pdf,doc,docx,xls,xlsx,zip" MaxSizeKB="20480" />
</CuteWebUI:UploadAttachments>
Typical code-behind
protected void Attachments1_FileUploaded(object sender, CuteWebUI.UploaderEventArgs e)
{
litLog.Text += "<div>Uploaded: " + Server.HtmlEncode(e.FileName) + "</div>";
}
protected void Attachments1_AttachmentAdded(object sender, CuteWebUI.AttachmentItemEventArgs e)
{
e.Item.SetCustomData("category", "invoice");
}
protected void Attachments1_AttachmentRemoveClicked(object sender, CuteWebUI.AttachmentItemEventArgs e)
{
e.Behavior = CuteWebUI.AttachmentItemBehavior.AutoRemove;
}
Working with the collection
foreach (CuteWebUI.AttachmentItem item in Attachments1.Items)
{
if (item.ShouldSave)
{
var path = Server.MapPath("~/App_Data/Attachments/" + item.FileName);
using (var input = item.OpenStream())
using (var output = System.IO.File.Create(path))
{
input.CopyTo(output);
}
}
}
Custom provider scenarios
CustomProvider is for pages that mix AjaxUploader temp files with records that already exist somewhere else.
The provider contract lives at IAttachmentProvider.