Menu

Thursday, September 23, 2010

Play Sound On Button Click C#

In Visual Studio
Go to solution explorer create new folder and name it sounds
Right Click on sounds folder then select Add Existing Item
Add your .wav files in sounds folder

Now go In Design View
Create New Button
Double click on that Button
Add A Namespace

using System.Media;

protected void Button1_Click(object sender, EventArgs e)
{    

         SoundPlayer sd = new SoundPlayer();
         sd.SoundLocation = Server.MapPath("~/sounds/filename.wav");
         sd.Play();
}


Done.

Download Source Code

1 comment: