Ajax文件上传控件 [英] Ajax File Upload Control

查看:62
本文介绍了Ajax文件上传控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AjaxFileUpload控件当用户尝试上传文件时我想要的是什么?

控件首先要检查是否超出了管理员定义的限制,即用户只能上传5个文件之后,他/她应该删除上传另一个文件,这意味着它只能上传5个不超过的文件。



所以基本上当用户尝试上传时,控件只是中断进程并显示你已超出文件限制,删除其中一个文件以上传新文件。



以及我想要的所有AjaxFileUpload因为它上传文件而不回发整个页面。



1)我可以限制在队列中上传的文件数量

2)类型上传文件也可以被限制



我遗失的一件事我不知道如上所述。



所以极客运行你的想法并给出答案.........

解决方案

Ajax上传控件HTML:

 <   ajaxctrl :asyncfileupload     id   =  AsyncFileUpload1    runat   =  server   上传者 风格  = 传统     xmlns:ajaxctrl   = #unknown >  
OnClientUploadError =uploadErrorHandlerOnUploadedComplete =Proce ssUploadOnClientUploadStarted =uploadStarted
Width =110pxClientIDMode =StaticStyle =position:absolute; z-index:2;不透明度:0;
filter:alpha(opacity = 0); border:solid 1px red;ToolTip =Upload photoThrobberID =UpdateProgress1/> < / ajaxctrl: asyncfileupload >





处理EventFunctions:



 function uploadErrorHandler(sender,args){
// < span class =code-comment> alert('无效的文件/文件大小'+ args.get_fileName()+'!');
}





 function uploadStarted(sender,args){
if (validateFileExtension (args.get_fileName())){
var fileSize = args.get_length();
if (parseInt(fileSize)> 3800000 ){
alert(< span class =code-string>' 文件超出文件大小限制。最大大小为19MB');
args.set_cancel( true );
return false ;
}
}
其他 {
alert( 无效文件' + args.get_fileName()+ '。支持的文件类型为'.jpg,.jpeg,.gif,.png,.bmp');
args.set_cancel( true );
return false ;
}
}





C#代码:



  protected   void  ProcessUpload( object  sender,AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
Boolean isValidFile = Utility.isValidFile(e.FileName, new String [] { .gif 。jpg 。bmp 。png});

if (isValidFile)
{
// 编写代码
}
else
{
ScriptManager.RegisterClientScriptBlock( this this .GetType(), img alert( '图像文件无效!'); true );
}
}


I am using AjaxFileUpload Control what i want that when user try to upload the file ,
the control first should check that is it exceeding the limit defined by the admin i.e user can only uploads 5 files after that he/she should have to delete to upload another file that means it can only upload 5 files no more than that.

So basically when user try to upload, the control just interrupt the process and display that you have exceed the file limits, delete one of the files to upload new one.

And all that i want in AjaxFileUpload because it uploads file without posting back the whole page.

1) i can limit the number of files to uploaded in queue
2) types of uploading files can also be restricted

the one thing i am missing and i don't know is stated above.

so geeks run your mind and give answer .........

解决方案

Ajax Upload Control HTML:

<ajaxctrl:asyncfileupload id="AsyncFileUpload1" runat="server" uploaderstyle="Traditional" xmlns:ajaxctrl="#unknown">
                                            OnClientUploadError="uploadErrorHandler" OnUploadedComplete="ProcessUpload" OnClientUploadStarted="uploadStarted"
                                            Width="110px" ClientIDMode="Static" Style="position: absolute; z-index: 2; opacity: 0;
                                            filter: alpha(opacity=0); border: solid 1px red;" ToolTip="Upload Photo" ThrobberID="UpdateProgress1" /></ajaxctrl:asyncfileupload>



Handle EventFunctions:

function uploadErrorHandler(sender, args) {
       //  alert('Invalid file/filesize "'+args.get_fileName()+'"!');
     }



function uploadStarted(sender, args) {
    if (validateFileExtension(args.get_fileName())) {
        var fileSize = args.get_length();
        if (parseInt(fileSize) > 3800000) {
            alert('File exceeds the file size limit.Maximum size is 19MB');
            args.set_cancel(true);
            return false;
        }
    }
    else {
        alert("Invalid file '" + args.get_fileName() + "'.Supported file types are '.jpg, .jpeg, .gif, .png, .bmp' ");
        args.set_cancel(true);
        return false;
    }
}



C# Code:

protected void ProcessUpload(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
       {
           Boolean isValidFile = Utility.isValidFile(e.FileName, new String[] { ".gif", ".jpg", ".bmp", ".png" });

           if (isValidFile)
           {
              //Write your code
           }
           else
           {
               ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "img", "alert('Invalid Image File!');", true);
           }
       }


这篇关于Ajax文件上传控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆