How to: Play a Sound from a Windows Form
This example plays a sound at a given path at run time.
This example requires:
That you replace the file name "c:\Windows\Media\chimes.wav" with a valid file name.
(C#) A reference to the System.Media namespace.
File operations should be enclosed within appropriate structured exception handling blocks.
The following conditions may cause an exception:
The path name is malformed. For example, it contains illegal characters or is only white space (ArgumentException class).
The path is read-only (IOException class).
The path name is null (ArgumentNullException class).
The path name is too long (PathTooLongException class).
The path is invalid (DirectoryNotFoundException class).
The path is only a colon, ":" (NotSupportedException class).