Search code examples
c#asp.netcsvrequiredfieldvalidator

RequiredFieldValidation for FileUpload


My code looks like this:

 <asp:Label ID="importLabel" runat="server" Text="Update Prices" CssClass="fieldlabel" />
                <asp:FileUpload ID="importFileUpload" runat="server" />

I need to add a required field validator to only accept .csv files. How would I do this?

Thanks!


Solution

  • <asp:RegularExpressionValidator ID="uplValidator" runat="server" ControlToValidate="importFileUpload" ErrorMessage="Only .csv files are allowed" 
                                ValidationExpression="(.+\.([Cc][Ss][Vv]))" />
    

    Added this REV to get it to work!