I am using ASP.NEt MVC . I want to upload .zip files for which I am using html input file upload control on my view. I want only .zip files to be uploaded. Is there any way or attribute to specify and achieve this?
thanks,
kapil
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is an ACCEPT attribute on the HTML file control that, in theory, can be used for this:
It accepts a comma-separated list of acceptable content-types. However, in practice most browsers don’t enforce this, so it can’t be relied upon. It does work in Opera, but doesn’t seem to work in IE or FireFox. There are also JavaScript methods to check, but these just check file extensions and so aren’t reliable.
The more reliable way is to check the actual content type of the uploaded file. You can do this via the HttpPostedFileBase.ContentType Property. Even then, some browsers may not send this correctly, so you can end up checking both file extensions and content types.