0

I use the FileUpload control to upload files to remote hosting server in C# ASPNET.

I have restrict the FileUpload control to upload a file type.

For example, I wanted to upload text file (txt) only so I put a validator, which allows txt only.

<asp:RegularExpressionValidator   
id="FileUpLoadValidator" runat="server"   
ErrorMessage="Upload Text file only."   
ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.txt)$"   
ControlToValidate="FileUpload1">  
</asp:RegularExpressionValidator> 

The typical Open File Dialog looks like figure below where you can see Windows Explorer like features to navigate through folders and select a file.

enter image description here

how to do when the browse button click event handler will show an open file dialog and users will be able to select only text files?

enter image description here

4
  • Funny - i'm no expert but checking msdn it seems that this is not possible, there is no field or something for the fileupload control. Commented Oct 14, 2020 at 8:23
  • Just add accept= Commented Oct 14, 2020 at 8:25
  • @VDWWD working! thanks... <asp:FileUpload ID="FileUploadControl" runat="server" accept="txt/*" /> Commented Oct 14, 2020 at 8:35
  • Just remeber that you can still upload other types. So check the data in the backend for the correct file type also. Commented Oct 14, 2020 at 8:38

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.