Basic doubts in C # (Sounds)

0

I'm new to the forum and new C # programmer as well.

I made basic software for college; a coffee maker. and I used sounds in it, however I indicated the sound in ("C: / users / ...") the path in my Pc.

When I do the ".exe" of this application, when I run on another PC other than mine it gives a miss on the sound and date.

I know the question is a beast, but how do I solve it?

    
asked by anonymous 04.09.2018 / 04:29

1 answer

6

Instead of using the direct path of the PC, it creates a folder in the root of the project called "Sounds" all the sounds it will use in the application you play.

When you use the sound you search as follows:

//Monta o caminho dos sons
var caminhoSons = Application.StartupPath + @"\Sons";

//Valida se a pasta existe
if (!Directory.Exists(caminhoSons))
{
    //Se não existir cria a pasta na raiz do projeto
    Directory.CreateDirectory(caminhoSons);
}

//Pega o som especifico
var musica1 = caminhoSons + @"\Musica.Mp3";

The Application.StartupPath command gets the folder where your project is running, so it can be on any PC, even on a Pen Drive (E:, F :) that it will get the correct project path, and so on the folder sounds within the project folder will always find the right path.

    
04.09.2018 / 08:00