ARTICLE

URL Extractor Client

Posted by Arun Nair Articles | Visual Basic 2010 April 26, 2005
This example demonstrates the use of Event handling in VB.NET. This application references the URLUtils DLL which is included along with the ZIP file. The URLUtils DLL which I made in VB uses the Winsock control to retrieve a URLs contents(with or without the header), it also retrieves the content length.
Download Files:
 
Reader Level:

Introduction

This example demonstrates the use of Event handling in VB.NET. This application references the URLUtils DLL, which is included along with the ZIP file. The URLUtils DLL, which I made in VB uses the Winsock control to retrieve a URLs contents (with or without the header), it also retrieves the content length. You can have a glance at the source code of the DLL (though it is in VB 6) to understand more. The DLL exposes two methods, startExtract and getStream. The method startExtract Public Sub startExtract(ByVal remotehost As String, ByVal extURL As String, ByVal getHeader As Boolean) starts the content extraction for the specified URL, the method getStream Public Function getStream As String reads the contents from the stream. There are three events provided by the DLL of which we will use only two for our example (contentLength, streamComplete). The contentLength event is invoked when the DLL has obtained the content-length from the header(this is generally set by the web-server and is an appromixate length of the content in bytes) of the URL. The streamComplete event is invoked when the DLL finishes extracting the URL.

In the application, create a Textbox (txtContents), Button (bnExtract), Label (lblCntLength).

Source Code

Imports System.ComponentModel
Imports System.Drawing
Imports System.WinForms
Public Class Form1
Inherits System.WinForms.Form
Private WithEvents ox As URLutils.IStreamURL
Public Sub New()
MyBase.New()
Form1 =
Me
'This call is required by the Win Form Designer.
InitializeComponent()
Dim URLutils As Object
ox = New URLutils.IStreamURL()
End Sub
'Form overrides dispose to clean up the component list.
Public Overrides Sub Dispose()
MyBase.Dispose()
components.Dispose()
End Sub
Protected
Sub bnExtract_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Call ox.startExtract("c-sharpcorner.com", "http://www.c-sharpcorner.com", True)
End
Sub
Public
Sub ox_contentLength(ByVal contentLength As Integer) Handles ox.contentLength
lblCntLength.Text =
CStr(contentLength)
End Sub
Public
Sub ox_streamComplete() Handles ox.streamComplete
txtContents.Text = ox.getStream
End Sub
End
Class

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Become a Sponsor