Hi i am make a small media player to play some mp3 file i have try many different way in which to make this program i finally resolved myself to using a dialog box because i could not get it done any other way with out having to worry about where the other person would install this program (because of directories).

you see i want to be able to bring this program to any one's computer and play the songs that i have in the resource folder.

I have use the following way:

dialog box:

private void LLRap_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            // Diectory of the music i want to play  

            dlg.InitialDirectory = @"c:\woods all projects\musicChoice\Rap";

            dlg.CheckFileExists = true;

            dlg.Multiselect = false;

            dlg.Filter = "Media Files(*.avi;*.mp3;*.mpg;*.mpa)" +

                   "|*.avi;*.mp3;*.mpg;*.mpa|" +

                 "All files (*.*)|*.*";

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                axWindowsMediaPlayer1.URL = dlg.FileName;

                BackColor = Color.Black; // colour to Black
                pbPac.Show();
                pbBeatles.Visible = false;
                pbIndie.Visible = false;
                pbMet.Visible = false;

            }
        }

Hard codeing in the address

private void LLRap_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

                axWindowsMediaPlayer1.URL = @"C:\Users\michael\Desktop\Wood All Projects\musicChoice\Rap\2pac.mp3";

                BackColor = Color.Black; // colour to Black
                pbPac.Show();
                pbBeatles.Visible = false;
                pbIndie.Visible = false;
                pbMet.Visible = false;
        }

finally not using the drive directory just the folders ( This is the part i will ask about after the code):

private void LLRap_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

                axWindowsMediaPlayer1.URL = "\\Users\\michael\\Desktop\\Wood All Projects\\musicChoice\\musicChoice\\Resources\\2pac.mp3";

                BackColor = Color.Black; // colour to Black
                pbPac.Show();
                pbBeatles.Visible = false;
                pbIndie.Visible = false;
                pbMet.Visible = false;
        }

You see what i want to be able to do it cut this last code to just use

axWindowsMediaPlayer1.URL = "\\Resources\\2pac.mp3";

but it wont find the file the reason i want to cut it to this is that if i don't

axWindowsMediaPlayer1.URL = "\\Users\\michael\\Desktop\\Wood All Projects\\musicChoice\\musicChoice\\Resources\\2pac.mp3";

no one else's computer will have this directory only mine but any one should be able to read
axWindowsMediaPlayer1.URL = "\\Resources\\2pac.mp3";
if you understand what i mean.

so is there any way to put in an address with out worrying about directories or do i just haver to use a dialog box

Dani AI

Generated

correctly avoids hard-coded absolute paths; is also right that the application’s folder should be the anchor for relative media paths. What was missing from the replies is a practical, deployment-safe workflow and the details that trip people up in Visual Studio (Build Action / Copy settings) plus an explanation of embedded resources vs file-based playback.

Add media files to the project (not the .resx resource designer) in a "Resources" folder, set Build Action = Content and Copy to Output Directory = "Copy if newer". At runtime construct a full path with Path.Combine against the app folder (Application.StartupPath or the assembly location) and check File.Exists before handing that path to the player — this avoids brittle string concatenation and mismatched slashes.

If mp3s are genuinely embedded in the assembly (manifest resource), the Windows Media Player control cannot play them directly from memory; the bytes must be written to disk first. Extract the manifest stream to a temp file (use Path.GetTempPath() and the actual manifest name from Assembly.GetManifestResourceNames()), then point the player to that temp file. Remember to remove temp files on exit if desired and to handle exceptions when the resource name isn’t found.

Troubleshooting checklist: confirm the files actually appear in bin\Debug or the published output, verify Build Action and Copy settings, use Path.Combine rather than manual paths, call GetManifestResourceNames() to confirm embedded resource names, and check permissions if running from protected locations. For distribution, include the media files with the installer/publish process so the runtime path resolves correctly.

When the program opens you need to save its current directory to a string, then append the resource folder name and song file name.

this method will return the directory that your application was open from.

private string GetAssemblyPath()
        {
            System.Reflection.Assembly exe = System.Reflection.Assembly.GetEntryAssembly();

            return System.IO.Path.GetDirectoryName(exe.Location);
        }

then you can do something like

axWindowsMediaPlayer1.URL = "GetAssemblyPath() + \\Resources\\2pac.mp3";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.