Catch Live Cricket Scores in your Website with ASP.NET Programming


.Net Programming will be fun only when you work with an interesting topic with fun you can acquire some knowledge about the technology and can use it in multiple scenarios.In this article i want to discuss such a topic which is entertainment and this can be implement for many scenarios.I am about to discuss with you regarding access of the other website contents in your website(Consume the website information only after acceptance of copy right laws from the original website owners).

Now a days the usage of internet has widely grown up.Hence the website owners wants to market thier websites in such a way that they want to publish their website with more popular events or information to increase the visitors/viewers count of the website irrespective or regardless of the website information/content they are publishing.Say for an Example a event like WORLD CUP Cricket is happening an Online News website information places an portion of the form or page or wants to scroll the contents beneath the page with Live scores and updation. So the viewer/visitor who is more interest to watch the news also can have a quick glance on the cricket scores.So the viewer get double benefits viewing the news and as well as glancing the cricket scores.I had taken the example of a Cricket scores The below are the few examples you can work with this WebClient class.

We can also fetch the book information and its availability from a online Book store website or We can also download the status of a movie tickets of a theatre from the Online Movie tickets Reservation website and still many more we can fetch the information from other websites.

In .Net classes for internet access can roughly divided into three groups.And it is the easiest way to consume the information of the remote Address url i.e The Webclient class.

The WebClient Class


Contains easy to use Methods for uploading and downloading data from a remote internet server.Behind the scenes.this class uses the webrequest and response of a classes.

The Webclient class has three methods of downloading the data
1)DownloadData-Returns a byte array from an internet address
2)DownLoadFile–Saves a file to the file system retrieved from internet address Ex:
webClient.DownloadFile( "http://mysite.com/myfile.txt", @"c:\myfile.txt");
.
3)Openread–Returns a stream from an internet address.

As i will give an example how to refresh the cricket scores with this.
To download the Scores information I am using the following url
http://scores.sify.com/index.shtml

Now my code look likes this.I will explain this how it works..


This Script will only refresh part of the page You can use iframes also instead of div block.And it will not disturb the rest of the contents.You can set the interval time i.e refresh time as per your requirement.

window.onload = setupRefresh;
function setupRefresh()
{
setInterval("refreshBlock();",3000);
}

function refreshBlock()
{
$('#block1').load(your aspx pagename);
}
block1 is the div tag and in between tags use the usecontrol.



The above code is for Refreshing part of the page

//WebUsercontrolpage.ascx

USING SYSTEM.NET;
USING SYSTEM.IO;
StreamWriter sw =null;
StreamReader sr=null;
string strresponse =string.Empty;
string strnew=string.Empty;
ArrayList arrlist =null;
WebClient wcMicrosoft =new WebClient();
System.Text.UTF8Encoding ObjUtF8Encoding =
new System.Text.UTF8Encoding();
Try
{
strresponse = ObjUtF8Encoding.GetString (wcMicrosoft.DownloadData("http://scores.sify.com/index.shtml"));
sw = new StreamWriter("C:\\Cricket.txt");
sw.WriteLine(strresponse);

}


catch(Exception)
{ sw.close();
sr = new StreamReader("C:\\Cricket.txt");
string line = sr.ReadToEnd();
}




finally
{
sr.Close();
sw.Close();
}



Usage of Text File



string strresponse =ObjUtF8Encoding.GetString(wcMicrosoft.DownloadData("http://scores.sify.com/index.shtml")); It is downloading data from the following url and returning as stream of bytes and getstring() method will convert string format which is in html format in the given example.

I had created one text file write those content(downloaded data) with streamwriter and read those contents with streamreader of the text file.I do n't want the entire information to be seen in my website only necessary contents to be displayed in my website.

I can manipulate the content of original website information ,manipulate according to the design specification of my Website and if i want to add an extra information i can do this with the help of text file.So for marking and searching the necessary contents(which i want to show in my website) i can use this text file.You can also use DownLoadFile() Method for this Example.

When your application hit the url of the remote address some times you get an exception that an underlying network connection closed or Your Remote adress url not responding.This all will occur when your remote address is not working (Network Failure/less speed of network connection in the remote server/recivers Network connection is slow/No. of users accessing the website is high)these are all the factors that you will get an exception and i do n't want to display blank contents as a part of my page.so i will retrive the last scores updation from the file.

Note : This Code will be Useful for sending and recieving Messages and Payment Gateways with minor changes in the code


Article by srirama
A Good advice from parent to a Child , Master to a Student , Scholar to an Ignorant is like a doctor prescribed pill it is bitter to take but when they take it will do all good for them --- Bhushan

Follow srirama or read 74 articles authored by srirama

Comments

Author: srirama18 Feb 2015 Member Level: Gold   Points : 0

Catch All Live Cricket Actions in the www.criccircle360.com



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: