AjaxUploader使用

一、简单上传(Simple Upload with Progress)

<CuteWebUI:Uploader ID="ajaxUploader" runat="server" InsertText="上传文件" OnFileUploaded="Uploader_FileUploaded">
</CuteWebUI:Uploader>

protected void Uploader_FileUploaded(object sender, UploaderEventArgs args)
{
  args.MoveTo(args.FileName);
}

二、多文件上传(Selecting multiple files for uploading)

<CuteWebUI:Uploader ID="ajaxUploader" runat="server" MultipleFilesUpload="true" InsertText="上传多个文件" OnFileUploaded="Uploader_FileUploaded">
</CuteWebUI:Uploader>

protected void Uploader_FileUploaded(object sender, UploaderEventArgs args)
{
    args.MoveTo(args.FileName);
}

三、自定义UI(Simple Upload with Progress (Customizing the UI))

<CuteWebUI:Uploader ID="ajaxUploader" runat="server"  InsertText="上传文件" InsertButtonID="ajaxUploaderInsert" CancelButtonID="ajaxUploaderCancel" ProgressCtrlID="ajaxUploaderProgress" ProgressTextID="ajaxUploaderProgressText" OnFileUploaded="Uploader_FileUploaded">
</CuteWebUI:Uploader>
<asp:Image ID="ajaxUploaderInsert" runat="server" AlternateText="上传" ImageUrl="http://ajaxuploader.com/sampleimages/upload.png" />
<asp:Panel ID="ajaxUploaderProgress" runat="server" BorderColor="Orange" BorderStyle="dashed" BorderWidth="2">
    <asp:Label ID="ajaxUploaderProgressText" runat="server" ForeColor="Firebrick"></asp:Label>
</asp:Panel>
<asp:Image ID="ajaxUploaderCancel" runat="server" AlternateText="取消上传" ImageUrl="http://ajaxuploader.com/sampleimages/cancel_button.gif" />

protected void Uploader_FileUploaded(object sender, UploaderEventArgs args)
{
    args.MoveTo(args.FileName);
}

四、自定义验证(Custom Validation)

<CuteWebUI:Uploader ID="ajaxUploader" runat="server"  InsertText="上传文件" OnFileUploaded="Uploader_FileUploaded">
    <ValidateOption AllowedFileExtensions="jpeg,jpg,gif,png" MaxSizeKB="100" />
</CuteWebUI:Uploader>

五、添加附件(Uploading multiple files like GMail)

<CuteWebUI:UploadAttachments ID="ajaxUploadAttachments" runat="server" InsertText="上传文件" MultipleFilesUpload="true"></CuteWebUI:UploadAttachments>
<asp:Button ID="BtnDeleteAll" runat="server" Text="全部删除" OnClick="BtnDeleteAll_Click" />

protected void BtnDeleteAll_Click(object sernder, EventArgs args)
{
    ajaxUploadAttachments.DeleteAllAttachments();
}

六、(Persist uploaded files through postback)

<CuteWebUI:UploadPersistedFile ID="ajaxUploadPersistedFile" runat="server" InsertText="上传文件" OnFileChanged="ajaxUploadPersistedFile_FileUploaded"></CuteWebUI:UploadPersistedFile>

protected void ajaxUploadPersistedFile_FileUploaded(object sender, PersistedFileEventArgs args)
{
    args.MoveTo(args.FileName);
}

七、模拟文件上传(Simulate File Upload)

<CuteWebUI:Uploader ID="ajaxUploader" runat="server" InsertText="上传" OnFileUploaded="ajaxUploader_FileUploaded"></CuteWebUI:Uploader>
<CuteWebUI:UploadAttachments ID="ajaxUploadAttachments" runat="server" InsertText="上传" OnAttachmentAdded="ajaxUploadAttachments_AttachmentAdded"></CuteWebUI:UploadAttachments>

protected void ajaxUploader_FileUploaded(object sender,UploaderEventArgs args)
        {
            using (Stream stream = args.OpenStream())
            {
                ajaxUploadAttachments.Upload(args.FileSize, args.FileName, stream);
            }
        }

        protected void ajaxUploadAttachments_AttachmentAdded(object sender,AttachmentItemEventArgs args)
        {
            Response.Write(args.Item.FileName);

八、允许最大上传数量(Limit the maximum number of files allowed to upload)

<CuteWebUI:Uploader ID="ajaxUploader" runat="server" InsertText="上传" MultipleFilesUpload="true" OnFileUploaded="ajaxUploader_FileUploaded"></CuteWebUI:Uploader>
<CuteWebUI:UploadAttachments ID="ajaxUploadAttachments" runat="server" OnAttachmentAdded="ajaxUploadAttachments_AttachmentAdded"></CuteWebUI:UploadAttachments>

private int GetVisibleItemCount()
{
    int count = 0;
    foreach (AttachmentItem item in ajaxUploadAttachments.Items)
    {
        count++;
    }
    return count;
}

protected override void OnPreRender(EventArgs e)
{
    base.OnPreRender(e);
    ajaxUploader.InsertButton.Enabled = GetVisibleItemCount() < 3;
}

protected void ajaxUploader_FileUploaded(object sender, UploaderEventArgs args)
{
    if (GetVisibleItemCount() >= 3)
        return;
    using (Stream stream = args.OpenStream())
    {
        ajaxUploadAttachments.Upload(args.FileSize, "ChangeName-" + args.FileName, stream);
    }
}

protected void ajaxUploadAttachments_AttachmentAdded(object sender, AttachmentItemEventArgs args)
{

}

九、手动开始上传(Start uploading manually)

<script type="text/javascript">
    function submitbutton_click() {
        var submitButton = document.getElementById('<%=BtnSubmit.ClientID %>');
        var uploadObj = document.getElementById('<%=ajaxUploadAttachments.ClientID %>');
        if (!window.filesuploaded) {
            if (uploadObj.getqueuecount() > 0) {
                uploadObj.startupload();
            } else {
                var uploadedcount = parseInt(submitButton.getAttribute("itemcount")) || 0;
                if (uploadedcount > 0) {
                    return true;
                }
                alert("Please browse files for uploading");
            }
            return false;
        }
        window.filesuploaded = false;
        return true;
    }
    function CuteWebUI_AjaxUploader_OnPostback() {
        window.filesuploaded = true;
        var submitbutton = document.getElementById('<%=BtnSubmit.ClientID %>');
        submitbutton.click();
        return false;
    }
</script>

<CuteWebUI:UploadAttachments ID="ajaxUploadAttachments" runat="server" ManualStartUpload="true" InsertText="上传" OnFileUploaded="ajaxUploadAttachments_FileUploaded"></CuteWebUI:UploadAttachments>
<asp:Button ID="BtnSubmit" runat="server" Text="开始上传" OnClientClick="return submitbutton_click()" />

protected override void OnPreRender(EventArgs e)
{
    BtnSubmit.Attributes["itemcount"] = ajaxUploadAttachments.Items.Count.ToString();
    base.OnPreRender(e);
}
protected void ajaxUploadAttachments_FileUploaded(object sender, UploaderEventArgs args)
{
 
}

 

posted on 2014-07-06 17:28  AngelLee2009  阅读(1915)  评论(0编辑  收藏  举报

导航