Click here to Skip to main content
13,301,591 members (93,776 online)
Click here to Skip to main content
Add your own
alternative version


11 bookmarked
Posted 20 Jan 2011

Add Sound File into Resource and Access It in .NET (C#)

, 20 Jan 2011
Rate this:
Please Sign up or sign in to vote.
How we can access sound file from resource, not from any other location


Actually, in this article, I am accessing the sound file from our project resource. Many times, we use sound in our project but in earlier days, I placed the sound file in a different location and then I access it. It's useful for those who want to hide resource of project and they want to make the project portable.

Using the Code

  1. Right click on your project name in solution explorer.
  2. Point the cursor on Add then choose Existing Item...
  3. Now go to the Location of your sound file and select that sound file.
  4. Now select your sound file in solution explorer, then Right click on it, choose Properties and change its Build Action property (Content to Embedded Resource)
  5. Build the program or one time Debug the program.
  6. Now if you want to play sound file when a particular Form is loaded, then use the given code in Form_Load event.
    NOTE: In this code, Dreamer.wav is the name of the sound file.


// Any source code blocks look like this
using System.Reflection;
using System.IO;
using System.Resources;
using System.Media;
using System.Diagnostics;
namespace Yournamespace
    public partial class Form2 : Form
        public Form2()
        private void Form2_Load(object sender, EventArgs e)
            Assembly assembly;
            Stream soundStream;
            SoundPlayer sp;
            assembly = Assembly.GetExecutingAssembly();
            sp = new SoundPlayer(assembly.GetManifestResourceStream

/*SoundPlayer sp = new SoundPlayer
(global::WindowsApplication1.Properties.Resources.yoursoundfilename); */

Points of Interest

Now, the time is 1:57 am, so I have to go. Actually, there are also some other techniques to access the sound file from resource. I just give one example for this which is mentioned in the above code in the comments.


  • 20th January, 2011: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

India India
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 1 Pin
Arlert4-Jan-15 2:10
memberArlert4-Jan-15 2:10 
QuestionNeeded to create Resources folder with wav file Pin
Nozrul14-Nov-14 2:08
memberNozrul14-Nov-14 2:08 
AnswerRe: Needed to create Resources folder with wav file Pin
ashishkumar00824-Nov-14 0:39
memberashishkumar00824-Nov-14 0:39 
QuestionSound File into Resource Pin
famontepeque13-Mar-14 10:39
memberfamontepeque13-Mar-14 10:39 
GeneralMy vote of 1 Pin
unpocoloco8-Sep-12 9:45
memberunpocoloco8-Sep-12 9:45 
GeneralMy vote of 5 Pin
Burak Tunçbilek19-Jun-12 5:50
memberBurak Tunçbilek19-Jun-12 5:50 
GeneralMy vote of 3 Pin
Baesky21-Jan-11 5:42
memberBaesky21-Jan-11 5:42 
GeneralMy vote of 3 Pin
Legol@s21-Jan-11 2:56
memberLegol@s21-Jan-11 2:56 
GeneralMy vote of 2 Pin
Volem20-Jan-11 23:25
memberVolem20-Jan-11 23:25 
GeneralC# Resources Pin
IGood20-Jan-11 12:37
memberIGood20-Jan-11 12:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171207.1 | Last Updated 20 Jan 2011
Article Copyright 2011 by ashishkumar008
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid