-3

I want to run an application to convert flac music type to wav music type. My application in C:\Users\Administrator\Documents\Application\convert.exe I want to run a command in this application with path of flac music file type the user choose. The command look like convert C:\User\Administrator\Documents\Example.flac D:\WavFile The C:\User\Administrator\Documents\Example.flac is the path the user choose in

    private void button1_Click(object sender, EventArgs e)
    {
        OpenFileDialog openFileDialog = new OpenFileDialog();
        openFileDialog.Filter = "Flac file(*.flac)|*.flac";
        openFileDialog.FilterIndex = 1;
        if (openFileDialog.ShowDialog() == DialogResult.OK)
        {
             string path = openFileDialog.FileName;
             //This is where i want to run the application with the path the user choose in the string up here
           
             //This where i play the wav file
            System.Media.SoundPlayer player = new SoundPlayer();
            Path.GetFileName(path);
            string name = path.Replace(".flac", ".wav");
            player.SoundLocation = @"D:\WavFile\" + name;
            player.Play();
        }
    }

So if you know the answer, let me know, thank you, i'm stuck in this part.

  • https://stackoverflow.com/questions/7008647/running-exe-with-parameters – Chetan Jul 26 '21 at 00:32
  • https://stackoverflow.com/questions/9679375/run-an-exe-from-c-sharp-code – Chetan Jul 26 '21 at 00:32
  • 1
    Does this answer your question? [Run an exe from C# code](https://stackoverflow.com/questions/9679375/run-an-exe-from-c-sharp-code) and [Use Process.Start with parameters AND spaces in path](https://stackoverflow.com/questions/17321289/use-process-start-with-parameters-and-spaces-in-path) –  Jul 26 '21 at 03:23

1 Answers1

0

Try this:

using System.Diagnostics;
using System.IO;

string tempPath = Path.Combine(@"D:\WavFile", Path.GetFileNameWithoutExtension(path) + ".wav");
Process.Start(@"C:\Users\Administrator\Documents\Application\convert.exe", $"\"{path}\" \"{tempPath\"")).WaitForExit();
player.SoundLocation = tempPath;
player.Play();

This will start the conversion application and wait for it to exit.

trinalbadger587
  • 1,905
  • 1
  • 18
  • 36