How to verify the file's type of the uploading file by the Codebehind?
In the demo.aspx, you use the validate control to verify the file's type in client browser , But when i rename the filename like a example.exe to example.rar , i can upload the file to the sever successfully. But i want to prevent this action.
Please tell me that how can i solve the issue by verify the true file's type with c sharp in codebehind. Thank you!
Re: How to verify the file's type of the uploading file by the Codebehind?
The FileContent property of the InputFile control will return a Stream from which you can read the contents of the file. Your code would then need to validate the contents (e.g. if you only allow images, you might verify that you can create an image from the stream). When you are done with the Stream, be sure to Close() it. If you don't NeatUpload will complain about the file already being used.
Since NeatUpload receives the upload file in chunks, would it be possible to validate the file type after receiving the very first chunk? This would avoid the users from sitting and waiting for large file to complete uploading only to find out that the server doesn't support their file type.
If this is supported, where should I begin the validation process?