- 60
- 03:41
- Channel: youtube
- 0
- Added: 17/04/2011
How to check file extension in file upload using asp.net regular expression There are 2 ways to check file extension 1.Server side 2.Client side Server side ------------- Languages: C#, VB etc... advantages: easy to implement, no need to know java script dis advantages: checks file extension after the file has been uploaded to the server. Client side ------------ Languages: Java Script advantages: checks the extension in the user's computer itself because java script runs in the browser. dis advantages: hard to implement, spend a lot of time searching for the code on the internet. We will focus on Client side validation because we dont want the user to wait for the file to upload and th…
MoreHow to check file extension in file upload using asp.net regular expression There are 2 ways to check file extension 1.Server side 2.Client side Server side ------------- Languages: C#, VB etc... advantages: easy to implement, no need to know java script dis advantages: checks file extension after the file has been uploaded to the server. Client side ------------ Languages: Java Script advantages: checks the extension in the user's computer itself because java script runs in the browser. dis advantages: hard to implement, spend a lot of time searching for the code on the internet. We will focus on Client side validation because we dont want the user to wait for the file to upload and then get a message saying that the file extension is not supported. users will get annoyed and they will never return to your site. Asp.net has a control for validating the user input called the "Regular Expression validator". What it does is it creates the java script code for us and matches the input with the expression By default it comes with expressions to validate phone number, email id etc.. There are books on how to write Regular expressions. Lets not get deep into it. So wat we will do is 1.Add file upload control 2.Add regular expression validator 3.Set the control to validate property of regular expression validator to the ID of file upload control 4.copy and paste the expression Thats it! I found this expression on a website ^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.gif|.jpg <b>...</b>