namespace WinFormsApp1
{
public partial class Form1 : Form
{
async Task DownloadMP3(string url, string path)
{
using (var httpclient = new HttpClient())
{
using (var stream = await httpclient.GetStreamAsync(url))
{
using (var fileStream = File.Create(path))
{
await stream.CopyToAsync(fileStream);
}
}
}
}
public Form1()
{
InitializeComponent();
}
async private void button1_Click(object sender, EventArgs e)
{
string url = "https://download.samplelib.com/mp3/sample-6s.mp3";
string path = "song.mp3"; // path = c:\Users\A\source\WinFormsApp1\WinFormsApp1\bin\Debug\net7.0-windows\WinFormsApp1.exe
await DownloadMP3(url, path);
label1.Text = "MP3 file downloaded successfully";
}
}
}
/*
* run:
*
*
*/