Code Examples
  Home arrow Code Examples arrow Page 4 - Download a Web Page using the WebClient
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
CODE EXAMPLES

Download a Web Page using the WebClient
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 62
    2006-09-13

    Table of Contents:
  • Download a Web Page using the WebClient
  • Creating a Windows project to use the WebClient Class
  • Know your options
  • Create a form using the WebClient Control

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Download a Web Page using the WebClient - Create a form using the WebClient Control


    (Page 4 of 4 )

    Another way of opening an URL to read its contents is to use the WebClient Control, which may be added to the Toolbox using the same procedure used for adding the WebBrowser control. Add a new form, WebClientControl.vb, to the project. From the Toolbox double click the WebClient control when the form is in the design view. Add a command button and a textbox whose multi-line property is set to true, with both scroll bars showing. The WebClient control gets to the component tray area as shown.

    To the click event of the command button add code as shown:

    Imports System.IO
    Public Class WebClientControl
     
        Private Sub Button1_Click(ByVal sender As _
        System.Object, ByVal e As System.EventArgs) _
        Handles Button1.Click
            Dim wc As New System.Net.WebClient
            Dim strm As New StreamReader _
            (wc.OpenRead("http://localhost/TestXMLHttp/TestClient.htm"))
            Dim s As String = strm.ReadToEnd
            TextBox1.Text = s
        End Sub
    End Class

    This time the OpenRead() method reads the TestClient.htm file on the local intranet. You are not referencing the class directly by the imports statement, rather you are instantiating a New WebClient. Otherwise using the StreamReader is similar to the previous case. When you run this form, your display appears as shown.

    Summary

    WebClient Class and the WebClient Control are very useful for interacting with web sites. The many properties and methods can be put to good use for importing any part of a web site. By creating a COM wrapper the controls can be called from VB 6. However the Inet and WebBrowser controls can continue to be used in VB6 programs. What is achieved using several lines of code in the Visual Basic 2005 Express Edition program can be achieved by two lines in a VB6 project, however one is object-oriented and the other is object-based. Whether Microsoft will continue to support VB 6 or not is another point to consider.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · You want to look at a web page in a windows application - the web client is a good...
     

    CODE EXAMPLES ARTICLES

    - Handling Animations and Bitmaps Using GDI+ f...
    - Download a Web Page using the WebClient
    - Creating a Chart using Data from a Database ...
    - The Basics of Charting with the MS Chart Con...
    - Searching Body Text with textRange: Enter th...
    - Searching Body Text with textRange: Building...
    - Searching Body Text with textRange, part 1: ...
    - First Steps in Programming
    - Programming in C
    - Quick Introduction to ASF,ASX, and Networkin...
    - SatView: Pointer Perfect, Part 2: Constructi...
    - SatView: Pointer Perfect, Part 1
    - Style Case Studies: Construction Unions
    - Creating an Engine for Games for Windows
    - Style Case Studies: Generic Callbacks





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway