In today’s world, people spend a lot of time catching up on several fields - education, science, sports, politics, and travel. As all this information is scattered across various websites on the internet, we usually tend to gather information from these websites and then collate it.
Accessing a single website that has all the information or services can help significantly reduce time. This approach brings multiple site content under a single umbrella and also reduces the user’s internet bandwidth. The user can easily access multiple websites using a single application URL in the web browser and need not enter the accessing website URL.
The WebClient wrapper class is one of the features available in .NET technologies. It defines the data extraction procedure, which is used to download resources with user specified URLs, and the class provides common methods for sending or receiving data from any local intranet, or Internet resource identified by a URL.
“System.Net.Sockets” is a namespace which contains the WebClient object or wrapper class. It is used to extract data from HTML, XML and CSV file types.
The WebClient class provides four methods for downloading data from a resource:
- The OpenRead method returns data from the resource as a stream
- The DownloadString method returns data from the resource as a string
- The DownloadData method downloads data from a resource and then returns a byte array
- The DownloadFile method downloads data from a resource to a local file
How it works
The target resource website provides data in the HTML format. Every ten minutes, we automatically get the updated data from the target website using the WebClient object in .Net. WebClient provides asynchronous methods for fetching webpage data as well; they are named similar to the synchronous methods.
The OpenRead method is used to retrieve the following information and then this is appended in the web application:
- Train status
- Electricity board
Possibility: We will be able to integrate the content from multiple sites in our application.
I have implemented a sample application using this logic and attached a screen shot below:
It takes more time to fetch the content from the target website if the internet connection is slow.
Supports the following platforms:
Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported) & Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported).
- Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1 & 1.0
- .NET Framework Client Profile