View Source of a Website using C#

This is a simple tutorial in which we are going to create a program that views a source of a website using C#. So, now let's start this tutorial! 1. Let's start with creating a Windows Form Application in C# for this tutorial by following the following steps in Microsoft Visual Studio 2010: Go to File, click New Project, and choose Windows Application. 2. Next, add two TextBoxes named TextBox1 for inputting a URL from the site, and TextBox2 for viewing the page source of the site. Add a WebBrowser named WebBrowser1 to display the site. Add also two Buttons named Button1 for displaying the URL for the website and Button2 for viewing the source of the website. Design your interface like this one below: design 3. Put this code to your code module:
  1. public class Form1
  2. {
  3.         private void Button1_Click(System.Object sender, System.EventArgs e)
  4.         {
  5.                 WebBrowser1.Navigate(TextBox1.Text);
  6.         }
  7.        
  8.        
  9.         private void Button2_Click(System.Object sender, System.EventArgs e)
  10.         {
  11.                 TextBox2.Text = WebBrowser1.DocumentText;
  12.         }
  13. }
We have code for Button1 for displaying the inputted website in the TextBox1 and displayed into the web browser. WebBrowser1.Navigate(TextBox1.Text) - is a syntax to for navigating the inputted URL in textbox1 and will display in the web browser. We also code for Button2_Click to view the page source coming from the WebBrowser1 to the TextBox2. DocumentText class is a method for viewing the page source of a website in the WebBrowser.

Output:

output output Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer If you have some queries, feel free to contact the number or e-mail below. Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Add new comment