Search code examples
asp.netsystem.drawing.imaging

Assuming ASP.NET and form upload, any way to ensure file is an image?


Is there any way to tell if the file is an image either through MIME type or some other way of inspection? The images are going into a gallery and I'll be resizing them as necessary and want to ensure, to the best I can, that the file I'm about to process with GDI is, in fact, an image.


Solution

  • Try to load the file into a Bitmap object. If if you get an exception then it isn't an image.