c# - Check if FileUpload is empty using Regular Expression -


I do if I can not fit it in one word it would check whether the file went chosen a file is the correct type and that If not, ignore the ID but both should be true, this file is of the right type and the file is selected by FileUploadControl.

Checking work extensions using the regular expression in the code given below:

  & lt; Li class = "three" & gt; & Lt; P & gt; Bulk input / upload inventory from file & lt; / P & gt; & Lt; Div & gt; & Lt; Asp: FileUpload id = "fileUploadControl" accept = "csv" runat = "server" /> & Lt; ASP: RegularExpressionValidator id = "regexValidator" runat = "server" ValidationGroup = "upload" ControlToValidate = "fileUploadControl" Error = "only allowed csv files" ForeColor = "red" ValidationExpression = "(* \ ([copy .. ] [Ss] [vv]) $) "& gt; & Lt; / ASP: RegularExpressionValidator & gt; & Lt; Br / & gt; & Lt; Asp: Button ID = "buttonUploadToInventory" runat = "server" Text = "upload" ValidationGroup = "upload" onclick = "buttonUploadToInventory_Click" / & gt; & Lt; Asp: Label ID = "statusLabel" runat = "server" text = "upload status: nothing uploaded" & gt; & Lt; / Asp: Label & gt; & Lt; / Div & gt; & Lt; / Li & gt;  

I would like to add a new section that checks to select a file so that I can display an error in the same label for it.

In a RequiredFieldValidator Add If a file is selected RFV will activate , And if a file is selected RegularExpressionValidator will activate

  & lt; ASP:. FileUpload id = "fileUploadControl" Accept = "CSV" Runat = "Server" /> & Lt; ASP: RegularExpressionValidator id = "regexValidator" runat = "server" ValidationGroup = "upload" ControlToValidate = "fileUploadControl" Error = "only allowed csv files" ForeColor = "red" ValidationExpression = "(* \ ([copy .. ] [Ss] [vv]) $) "& gt; & Lt; / ASP: RegularExpressionValidator & gt; & Lt; Asp: RequiredFieldValidator ID = "requiredValidator" runat = "server" ValidationGroup = "upload" ControlToValidate = "fileUploadControl" Error = ForeColor = "red" & gt "select a file"; & Lt; / ASP: RegularExpressionValidator & gt;  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -