I am using ASP.NET MVC and I\'ve an action that uploads the file. The file is being uploaded properly. But I want width and height of the image. I think I need to convert th
If you are sure, that the source is image and doesn't need editing, you can do it easily as described here
[HttpPost]
public void Index(HttpPostedFileBase file)
{
if (file.ContentLength > 0)
{
var filename = Path.GetFileName(file.FileName);
System.Drawing.Image sourceimage =
System.Drawing.Image.FromStream(file.InputStream);
}
}
To secure the file is image, add javascript validation to View by adding accept attribute with MIME type to input tag
and jQuery validation script
$.validator.addMethod('accept', function () { return true; });
The whole solution can be found here