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# ?
How do I do this in C# ?
public partial class Form1 : Form
{
System.Media.SoundPlayer m_player = new System.Media.SoundPlayer();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
m_player.SoundLocation = textBox1.Text;
m_player.Play();
}
catch (System.IO.FileNotFoundException ex)
{
MessageBox.Show("Could not file file: " + textBox1.Text + "\n" + ex.Message);
}
catch (System.InvalidOperationException ex)
{
MessageBox.Show("File was not a valid .WAV file: " + textBox1.Text + "\n" + ex.Message);
}
catch (Exception ex)
{
MessageBox.Show("Unknown exception: " + ex.Message);
}
}
}
Comment