How to download web content with .NET.
This morning I created another video tutorial, this one on downloading web content to use inside your .NET application. The tutorial goes over downloading content with the WebClient class as well as a brief intro to multithreading with the BackGroundWorker class.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Net; namespace WebClientDemo1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { bgWorker1.RunWorkerAsync(); } private void bgWorker1_DoWork(object sender, DoWorkEventArgs e) { try { WebClient webC = new WebClient(); bgWorker1.ReportProgress(1, webC.DownloadString(textBox1.Text)); } catch (Exception ee) { Console.WriteLine(ee.Message); } } private void bgWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) { if (e.ProgressPercentage == 1) { textBox2.Text = (string)e.UserState; } } } }
