برای بررسی صحت فرمت فایل های آپلودی در ASP.net میتوان از قطعه کد زیر استفاده کرد.
در صورتی که کنترل FileUpload به صورت زیر باشد:
- <asp:FileUpload ID="fluFile" ClientIDMode="Static" runat="server" />
میتوان از قطعه کد زیر استفاده کرد:
- $(document).ready(function () {
- $("#<%= fluFile.ClientID %>").change(function () {
- var fileExtension = ['zip', 'rar', 'pdf', 'doc', 'docx', '7z', 'ppt', 'pptx', 'xls', 'xlsx', 'xlms', 'pps'];
- if ($.inArray($(this).val().split('.').pop().toLowerCase(), fileExtension) == -1) {
- alert("فرمت های قابل قبول برای فایل : " + fileExtension.join(', '));
- }
- });
- });