ARTICLE
URL Extractor Client
Tags: .NET, Button, DLL, Event handling, events, How to extract content of specified URL, Label, TextBox, URL, URL Extractor, VB.NET, Winsock control
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:
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