I need a method that could tell me if a file is image, audio or video file. Can I do this with C#?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It depends how robust you want it to be.
The simplest way to do it is to check the extension, like this:
EDIT: For those who really want LINQ, here it is:
Note that a file’s extension is not a reliable indicator of its content; anyone can rename a file and change its extension.
If you don’t have the extension, or if you don’t trust it, you can read the beginning of the file and see if it matches file signatures for common media formats.