PLAY audio file c# code example

Example 1: c# play sound

System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"c:\mywavfile.wav");
player.Play();

Example 2: how to play a sound on button click c#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Media;

namespace soundboard
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
           SoundPlayer splayer = new SoundPlayer(@"D:\google downloads\[ontiva.com] Rick Astley - Never Gonna Give You UP (video)-320k.wav");
            splayer.Play();
        }
    }