Hi all, 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
Hi all, 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
Using the standard html input control, there isn't a way. You could use Flash upload controls which are more customizable. SWFUpload is an example.
In my opinion in all cases you need to perform a server side validation of the uploaded file extension and content.
There is an ACCEPT attribute on the HTML file control that, in theory, can be used for this:
<input type="file" name="ZipFile" accept="application/x-zip" />
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.
Never trust the client!
An HTML or Javascript-validation is worth nothing. You could work around this! So validate the files and filetypes on the server. For example with PHP, JSP, etc.