Go ahead and open up your text editor or whatever you use to write your code in. On the first line we need to add a reference.
using System.Net;Now lets go ahead and create a class and put the main statement in it.
using System.Net;
class Program
static void Main(string[] args)
To make things nice and clean lets go ahead and create a string called "url" and put in whatever url we want to get the source code of. Then lets go ahead and use that with the HttpWebRequest method.
using System.Net;
class Program
static void Main(string[] args)
string url = "http://www.quack-ware.com";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
Alright were doing great, now lets get the response...
using System.Net
class Program
static void Main(string[] args)
string url = "http://www.quack-ware.com";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Now that we have the response we have to call a StreamReader to read the response stream. We also have to add a reference to System.IO to use the StreamReader.
using System.Net;
using System.IO;
class Program
static void Main(string[] args)
string url = "http://www.quack-ware.com";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
We're almost done. Now lets get the source code into string format and close the StreamReader...
using System.Net;
using System.IO;
class Program
static void Main(string[] args)
string url = "http://www.quack-ware.com";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
string soureCode = sr.ReadToEnd();
sr.Close();
All done, now you can display the string containing the sourceCode and manipulate it however you want!
How to Get the Source Code of a Website Using C# Programming Language Check For The New Release in Health, Fitness & Dieting Category of Books NOW!
Written by Curtis Larson http://www.Quack-Ware.com Free programs, downloads, internet tools, and programming resources.
watch mobile phone Buy 7 8 X 10 4 Rectangular Home Best Price Golf Cart Ultimate Light Kit Upgrade Cheap Deals Mason 5C025 Pad Anti Vibration