What is the correct way to add files to the Resources of a VB.net project

Cynolycus 285 Reputation points
2025-11-23T12:25:22.6766667+00:00

I have been having trouble getting wave files into the resources of this project.

I tried to add the wave files by right clicking on 'Resources' in the Solution Explorer and selecting 'Add' and 'Existing Item'

That added the files to the Resources list but I couldn't select it with code.

I restored my files by loading a copy of a backup to ensure that there were no problems with project and then tried a different way to add the wave files.

I opened Resource Explorer by clicking on 'View', hovered over 'Other Windows' to open the next list where I clicked on 'Resource Explorer'.

After opening Resource Explorer I clicked the green + symbol which opened the 'Add New Resource to Form1' window.

In this window I changed the Type to audio.

I clicked on 'Select File' navigated to the folder and then selected the 'Alarm01.wav' file.

To ensure I had a valid and working .wav file I copied the 'Alarm01.wav' file from C:\Windows\Media folder to another, which will play directly from the folder using the 1st line in the Button1 _Click event.

The Name field took on the name of the file and the only option for 'Add To File' was 'Form1' so I didn't change these.

The file showed up under the 'Resources'

I then tried adding the resource to the same code that would play the file from it's original folder this is the 2nd line in the Button1 _Click event, but I keep getting the same result, My.Resources.Alarm01 is underlined in red with the error 'BC30456: 'Alarm01' is not a member of 'Clock_App_V1.2.MyResources'.

There is more code for the mediaplayer but this is all that was needed to play the sounds.


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        FullAlarmFilePath = "D:\Desktop\New folder\Alarm01.wav"
        'FullAlarmFilePath = My.Resources.Alarm01.ToString
        'FullAlarmFilePath = My.Resources.AarrowUp2.ToString
        PlaySound()
    End Sub

    Private Sub PlaySound()
        AxWindowsMediaPlayer1.URL = FullAlarmFilePath
        AlarmSounding = True
        AxWindowsMediaPlayer1.Ctlcontrols.play()
    End Sub

As an experiment I added another line, the 3rd line in the Button1 _Click event which selects a bitmap image to play, but I didn't get the error '<name>' is not a member of '<classname>'.

Obviously if I clicked on the button to play it then mediaplayer would tell me that it wasn't the correct format.

This showed me that the bitmap was considered as part of the resources and that I could select it when typing the code, but I can't select Alarm01.wav that is part of the same resources.

I remember having the same problem a long time ago with images and found that if I added them by using the background image of a control, such as a button or picture box it would work.

That is how I have been adding images ever since and is how I added the image used in the code.

So I tried adding a bitmap the same way as I added the audio and found that it gives the same result, when writing code it doesn't recognise that the bitmap is there.

It must be something to do with how I'm adding the files.

Does anybody know what I am missing or doing wrong, because I can't see what it could be.

Developer technologies | VB
0 comments No comments
{count} votes

Answer accepted by question author
  1. Viorel 125.6K Reputation points
    2025-11-23T19:20:08.56+00:00

    Try another king of resources.

    Right-click the project in Solution Explorer, go to Add, New Item, and add the “Alarm01.wav” to project.

    Select the added “Alarm01.wav” in Solution Explorer, right-click, go to Properties (or press <F4>). Set “Copy to Output Directory” to “Copy if newer”.

    Use this code:

    private void button1_Click( object sender, EventArgs e )
    {
        axWindowsMediaPlayer1.URL = Path.Combine( Application.StartupPath, "Alarm01.wav" );
        axWindowsMediaPlayer1.Ctlcontrols.play( );
    }
    

2 additional answers

Sort by: Most helpful
  1. Q&A Assist
    2025-11-23T12:25:37.0133333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To correctly add audio files like .wav files to the resources of a VB.NET project, follow these steps:

    1. Open Resource Explorer: In Visual Studio, go to View > Other Windows > Resource Explorer.
    2. Add New Resource: Click the green + symbol to open the Add New Resource to Form1 dialog.
    3. Select Type: Change the type to Audio.
    4. Select File: Click on Select File, navigate to your .wav file (e.g., Alarm01.wav), and select it.
    5. Name the Resource: The name field will automatically take the name of the file. Ensure that the Add To File option is set correctly (it should be set to the form where you want to use it).
    6. Check Resource Access: After adding the resource, you should be able to access it in your code using My.Resources.Alarm01.

    If you are encountering the error 'Alarm01' is not a member of 'Clock_App_V1.2.MyResources', it could be due to:

    • The resource not being properly added to the project. Ensure you see it listed under My.Resources.
    • The resource name might not match what you are trying to access in code. Check for any typos or case sensitivity issues.
    • If you added the resource in a specific form, ensure you are accessing it from that form's context.

    If you still face issues, consider removing the resource and re-adding it, ensuring you follow the steps correctly. Also, check if the project is properly built after adding resources, as sometimes changes may not reflect until a rebuild is performed.


  2. Bruce (SqlWork.com) 81,971 Reputation points Volunteer Moderator
    2025-11-23T19:33:30.0633333+00:00

    If a file is added as a resource, it is not a separate file, but part of the exe. The contents are available as a stream via the generated resource manager code. Pass the stream instead of file name.

    https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-resources-resourcereader


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.