Let's say somebody may change the extension of a .doc or .mp3 file to .wav, in my application, I want to check to make sure if a file is actually a .wav file.
How do I do this in C# ?
Please let me know,
Thanks,
Rocco
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Mar 5, 2010, 9:47 PM
i the case where you need that your program identifies the Actual File Extension you need to Find Some Patterns in Bytes Which can identify which pattern File Belongs to and then identify particular Extension ..like mp3 files having tag in the Beginning of it so you can identify it ..
Phuc HoangPosted Mar 5, 2010, 4:59 PM
Thanks for your answer. However, your suggestion doesn't solve the problem as I have described the situation in my previous post that if a user deliberately change the a file extension from .doc or .mp3 to .wav ....
In this case, the method File.Extension(path) still returns .wav but indeed the file is a .doc or .mp3 file.
NainilPosted Mar 5, 2010, 4:46 PM
You can use File.Extension(path) to find out the extension for a particular file.
File.extension(@"C:\music.wav") returns a ".wav" string.
Hope this helps.