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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Nainil148 reputationPosted Mar 5, 2010, 11:46 AM EST
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.
Phuc Hoang4 reputationPosted Mar 5, 2010, 11:59 AM EST
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.
Kirtan PatelRank #292 · 8.6K reputationPosted Mar 5, 2010, 4:47 PM EST
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 ..