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
I can upload file in MVC3 (C#) by using HttpPostedFileBase but i want to know more about upload file as like...
File Size
File Type
please help me
File Size
Use file.ContentLength
where file is you HttpPostedFileBase
variable.
File Type
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.
How can can i filter file upload by file type
HTML5 supports specifying content type:
<input type="file" name="file" accept="image/*" />
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.