F
F
forven2015-07-09 22:35:06
ASP.NET
forven, 2015-07-09 22:35:06

How to download an audio file?

There is a page where I can download the file by right clicking "Save As". How to do it programmatically?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ar4ebaldello, 2015-07-11
@forven

using (var client = new System.Net.WebClient() { Encoding = Encoding.UTF8 })
{
    // Скачиваем код страницы
    var page = client.DownloadString("http://PageAddress");
    // Находим ссылку
    var source = System.Text.RegularExpressions.Regex.Match(page, $"(?<=href=\").*?\\\.mp3(?=\")").Value;
    // Скачиваем файл
    client.DownloadFile(source, "audio.mp3");
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question