Click here to Skip to main content
12,624,174 members (34,201 online)
Click here to Skip to main content
Add your own
alternative version


24 bookmarked

WebResourceProvider VB.NET style

, 30 Aug 2002
Rate this:
Please Sign up or sign in to vote.
Ravi Bhavnani's WebResourceProvider ported to the .NET Framework


First of all I have to thank Ravi Bhavnani for his excellent WebResourceProvider article.

I just took the opportunity to translate the code into VB.NET and tried to use as much .NET Framework functionality as possible.

Please refer to Ravi Bhavnani's article for more in-depth information about the idea of WebResourceProviders.

The source code provided with this article is a Visual Studio .NET project with the base class WebResourceProvider and a demo application including two derived classes:

  • stock quotes
  • the translation of a piece of text (which uses also a POST request)

How it Works

You use WebResourceProvider by deriving your own resource provider class from it, and overriding any of these virtual methods:

  • Init
  • ConstructUrl
  • IsPost()
  • GetPostData()
  • ParseContent()
  • MoreAvailable()

WebResourceProvider provides an assortment of methods to help parse downloaded content. They are:

Method   Purpose
At   Checks whether current location is at a string
AtExact   Case sensitive version of at()
SkipTo   Advances current location to next occurence of a string
SkipToExact   Case sensitive version of SkipTo()
SkipBackTo   Advances current location to previous occurence of a string
SkipBackToExact   Case sensitive version of SkipBackTo()
ExtractTo   Extracts text from current location to the start of a string
ExtractToExact   Case sensitive version of ExtractTo()
ExtractToEnd   Extracts text from current location to end of content
GetIndex   Returns current location
GetLinks   Returns HREF and IMG links in content
ResetIndex   Sets current location to start of content
ResetIndex   Sets current location to start of content
StoreIndex   Stores current location
RestoreIndex   Restores the prevoiusly stored location
RemoveComments   Removes comments from content
RemoveScripts   Removes scripts from content
RemoveEnclosingAnchorTag   Removes anchor tag enclosing a string
RemoveEnclosingQuotes   Removes quotes enclosing a string
RemoveHtml   Removes HTML from a string
Trim   Removes leading and trailing whitespace from a string
ReplaceSpecialChars   Replace special HTML characters like ampersand, umlaut, etc. to its character representation

Sample Resource Providers

There are two sample resource providers in the source code:

The QuoteProvider class works by posting a request to Yahoo's basic stock quote form and parsing the returned information.

The TranslationProvider class works by posting a request to Google's translation engine and parsing the returned information.  The request includes the translation mode. The sample performs a reverse translation and presents it along with the original text for comparison purposes.

Using WebResourceProvider

To use WebResourceProvider do the following:

  1. Start building any VB.NET project in Visual Studio .NET
  2. Add WebResourceProvider.vb to your project
  3. Create a new class which inherits from WebResourceProvider
  4. Override the ConstructUrl() method in your derived class. This method specifies the URL to be downloaded.
  5. Override the ParseContent() method in your derived class. This method extracts information from the downloaded content and stores it in the derived class' member variables.
  6. Optionally override other WebResourceProvider virtual methods. See the source code of the sample resource providers included in the demo project for examples.
  7. Run and debug your code from within Visual Studio .NET


WebResourceProvider uses the following code written by others:

Revision History

  • 11 June 2002 Initial version of article.
  • 27 August 2002 Some bugs fixed, added functions (SkipBackTo, SkipBackToExact, StoreIndex, RestoreIndex, ReplaceSpecialChars)


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Switzerland Switzerland
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralStock up or down Pin
Michael J. Collins24-Mar-04 5:59
memberMichael J. Collins24-Mar-04 5:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.161128.1 | Last Updated 31 Aug 2002
Article Copyright 2002 by Cello
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid