I can upload file in MVC3 (C#) by using HttpPostedFileBase but i want to know more about upload file as like…
- How to get
File Size
- How to get
File Type
- How can can i filter file upload by file type
please help me
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.
Use
file.ContentLengthwhere file is youHttpPostedFileBasevariable.You could use the extension of the filename, but obviously not 100% reliable. If you want a bullet-proof solution you will have to use heuristics. For example look at the contents of the uploaded file to try to guess its type. For example to test for known image formats you could use the the following technique. I also wrote another post about validating against known image formats using a custom validation attribute.
HTML5 supports specifying content type:
If your browser doesn’t support HTML5 you will have to use some other technology such as Flash or something. You could use existing plugins such as Uploadify or Plupload which provide this functionality by testing the capabilities of the client browser and falling back progressively.
There simply is absolutely nothing you could do with native HTML and javascript in a say IE7 in order to filter the contents of the file input box.