user34537
user34537

Reputation:

How do i verify a file format?

Basically this question except i am using ASP.NET. How do i take a given file and check if it is

The solution does not need to check all of these but if i can get a few to check all of these then great.

Upvotes: 0

Views: 3804

Answers (2)

Justin Ethier
Justin Ethier

Reputation: 134227

You can try to either:

  • Find documentation for the file format and check for known bytes in the file header, etc
  • Attempt to load the file using an API - if the file loads successfully then you know it is of the proper type.

For example, here is an example of how to verify an image file: validate-image-from-file-in-c#

Of course, the mime type and/or file extension can give you a good guess of what file format you are dealing with, but (depending on the source) you should not rely on it exclusively.

Upvotes: 2

Winston Chen
Winston Chen

Reputation: 6879

Given the variety of your file types, checking the extension may be the best option. Anyone has other thoughts?

Upvotes: 1

Related Questions