ASP Fileupload Accept Attribute
asp.net, file-upload
Solution
Try following:
<asp:FileUpload ID="fuTest" runat="server" />
<asp:RegularExpressionValidator ID="regexValidator" runat="server" ControlToValidate="fuTest" ErrorMessage="Only csv files are allowed" ValidationExpression="(.*\.([cC][sS][vV])$)"></asp:RegularExpressionValidator>
- Internet Explorer 9 does not care about the accept attribute. Refer http://www.stackoverflow.com/questions/181214/
- Do not use this attribute as a validation tool. File uploads should be validated on the server. Refer http://www.w3schools.com/tags/att_input_accept.asp .
Problem
I've tried a plenty ways to limit the ASP FileUpload by file extension. Using asp-validation, checking the file codebehind, javascript, and so on. now i found a new way to limit the selectable files: ``` <asp:FileUpload ID="fuTest" runat="server" accept=".csv" /> ``` i added the accept attribute. is this a valid way according to ASP.net? The ``` <asp:Fileupload ``` is rendered as ``` <intput type="file" ``` and this attribute is used without any errors and works like a charm. Is this valid an exist any restrictions i have not noticed yet?