Как проверить все файлы в нескольких загрузчиках файлов с помощью ASP .NET C#
In my application i have a file uploader which accept multiple files in a single fileupload control i need to validate the extensions of all the files in that file uploader in such a way that it should accept only doc and docx suppose if i select 5 fils in a file uploader all the files should be of -b.doc,-b.docx,-b.DOC and -b.DOCX if there are any other extensions other than these four i should show an error message and clear the files which are in that particular file uploader how can i do this below is my file uploader code.
<asp:FileUpload ID="filDoc" runat="server" multiple="multiple"/>
Что я уже пробовал:
i tried the below code the problem is it is showing alert instead it should show error message after displaying the error message it should cleat the files in file uploader but it is showing two files
<asp:FileUpload ID="filDoc" runat="server" multiple="multiple" onchange ="checkFileExtension(this);"/>
<script type="text/javascript"> function checkFileExtension(elem) { var filePath = elem.value; if (filePath.indexOf('.') == -1) return false; var validExtensions = new Array(); var ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase(); //Add valid extentions in this array validExtensions[0] = 'doc'; //validExtensions[1] = 'pdf'; for (var i = 0; i < validExtensions.length; i++) { if (ext == validExtensions[i]) return true; } alert('The file extension ' + ext.toUpperCase() + ' is not allowed!'); return false; } </script>