Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
I have to upload the file which has the extension .fnm
Here is how I am validating:

VB
If String.Compare(System.IO.Path.GetExtension(fuUpload.FileName), ".fnm", True) <> 0


And its working fine. It only uploads the file having the extension .fnm.

The problem is that when someone manipulates the file extension like changes .txt or .doc to .fnm, it bypasses the validation and gets uploaded.



Is there any way to validate file type other than its extension? Or any other method to validate. Please suggest.
Posted
Updated 25-May-16 2:33am
Comments
phil.o 8-Oct-13 9:18am    
What is the formal description of the .fnm file format?

There are a couple of ways, first you can read the mime type, but only well known file types will be recognized. In this case, I think the best way would be to open and read the file and validate to file's content before handling it. That's to only way to be sure.
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900