0

Is it possible to download a file using the download link URL using C# WPF Application without opening the browser? For example: The link - http://example.url.com when typed into the address bar of the browser automatically downloads a file. How can i download this file upon a button click in WPF application (C#) without opening the browser?

TIA.

Pruthvi Shetty
  • 11
  • 1
  • 1
  • 8

1 Answers1

10

You can use WebClient.DownloadFile, if you want to download a specific file and store it on your machine:

using (WebClient client = new WebClient())
{
    client.DownloadFile(remoteFilename, localFilename);
    ...
}

or WebClient.DownloadString, if you want the page's content as a string:

using (WebClient client = new WebClient())
{
    string reply = client.DownloadString (address);
    ...
}
Yurii
  • 4,811
  • 7
  • 32
  • 41