多个文件的fileupload控件,扩展检查

时间:2015-01-14 04:35:00

标签: javascript jquery asp.net file-upload asyncfileupload

我有上传多个文件的文件上传控件。喜欢这个

 <ajaxToolkit:AsyncFileUpload ClientIDMode="Static" name="aa[]" BackColor="Azure"
         ForeColor="Black" OnClientUploadError="uploadError" OnClientUploadStarted="abc"
         multiple="multiple" OnClientUploadComplete="uploadComplete" runat="server" 
         ID="AsyncFileUpload1" Width="400px" CompleteBackColor="White" 
         UploadingBackColor="#CCFFFF" OnUploadedComplete="AsyncFileUpload1_UploadedComplete" />

我想只允许jpg png和gif文件类型上传。

如何在javascript和jquery中实现这一点?

所以真实的是如何从fileupload控件和检查扩展名访问文件名?

1 个答案:

答案 0 :(得分:0)

您可以按如下方式使用函数OnClientUploadStarted在此事件中使用函数名称,如下所示

OnClientUploadStarted="AssemblyFileUpload_Started"

并编写如下函数

function AssemblyFileUpload_Started(sender, args) {
    var filename = args.get_fileName();
    var ext = filename.substring(filename.lastIndexOf(".") + 1);
    if (ext != 'png') {
        throw { 
            name:        "Invalid File Type", 
            level:       "Error", 
            message:     "Invalid File Type (Only .png)",
            htmlMessage: "Invalid File Type (Only .png)" 
        }
        return false;
    }
    return true;
}