Determine actual file type

  • Thread starter Thread starter Mac McMicmac
  • Start date Start date
M

Mac McMicmac

I need to verify that files users copy to a server are of a specific file
type (.jpg, gif, mpeg, or wav) - and I don't want to assume that the file
extension correctly represents the actual file type. How can this be done?

Thanks in advance.
 
You'd have to know how to read each file type that you want to validate.
This can become overwhelming. I suppose you could have a control that knows
how to read each file type try to open it and validate it that way (i.e.
have the System.Drawing.Image class open the .jpg and make sure you don't
get an exception) ... else you need to know the actual format of the files
so you can do it by hand. Be warned, it could get ugly.

Someone out there may have written some libraries that do this for you for
some types. If so, try to track those down.

Adam
 
Thanks for the warning. I understand what you said was true before .NET, and
was kind of hoping that .NET miraculously offered some breakthrough
assistance on this topic. I guess I'll stick to the method of trapping
errors if/when the file being processed is not of the assumed type (per the
file's extension).
 
Back
Top