How to verify the file's type of the uploading file by the Codebehind?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to verify the file's type of the uploading file by the Codebehind?

Guest-536

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!

Reply | Threaded
Open this post in threaded view
|

Re: How to verify the file's type of the uploading file by the Codebehind?

Dean Brettle
Administrator
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.
Reply | Threaded
Open this post in threaded view
|

Re: How to verify the file's type of the uploading file by the Codebehind?

Guest-536

I wish that you can give me a example code that prevent upload  the type of   exe . 

Please help me solve this question . I am a new study  asp.net  boy. 

Thanks!

Reply | Threaded
Open this post in threaded view
|

Re: How to verify the file's type of the uploading file by the Codebehind?

Dean Brettle
Administrator
Sorry, I can't help you.  Determining whether a file is executable is not specific to NeatUpload.
Reply | Threaded
Open this post in threaded view
|

Re: How to verify the file's type of the uploading file by the Codebehind?

Guest-536

When i rename the filename like  a  example.exe  to  example.rar , then click the button to upload the file, how to let the progress display not started.

Please give me a  solution, Thanks.

Reply | Threaded
Open this post in threaded view
|

Re: How to verify the file's type of the uploading file by the Codebehind?

Loc Pham
In reply to this post by Dean Brettle
Hi Dean,

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?

Thanks,
Loc