If you need to download the web content synchronously using C# , you can use the WebClient class that is defined in the System.Net namespace.
Below is a sample code snippet demonstrating how to download web content synchronously in c#.
How to Download Web Content synchronously in C# ?
using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Net; namespace AbundantcodeApp { internal class Program { private static void Main(string[] args) { // How to Download Web Content synchronously in C# ? using (WebClient webClient = new WebClient()) { try { webClient.DownloadFile("http://Abundantcode.com", "output.html"); } catch (WebException ex) { Console.WriteLine(ex.Message); } } Console.ReadLine(); } } }
The output file is generally saved in the same folder where the exe exists.
Leave a Reply