string ret; try { // The Path to the Yahoo Quotes Service string fullpath = @"http://quote.yahoo.com/d/quotes.csv?s="+symbol+"&f=sl1d1t1c1ohgvj1pp2owern&e=.csv";
// Create a HttpWebRequest object on the Yahoo url
// Create a StreamReader object and pass the Yahoo Server stream as a parameter
StreamReader strm = new StreamReader(webresp.GetResponseStream(), Encoding.ASCII);
// Read a single line from the stream (from the server) // We read only a single line, since the Yahoo server returns all the // information needed by us in just one line.
ret= strm.ReadLine();
// Close the stream to the server and free the resources.
<Html> <head> <script runat=server> // Wire up the onClick event for a button protected void button1_Click(object sender, EventArgs e) { file://Create a object of the class DailyStock (the proxy class) DailyStock ds = new DailyStock();
// Call the GetQuote method of the proxy class DailyStock and // pass the symbol string from the textbox string res = ds.GetQuote(symbol.Text);
// The returned string has values which are separated // by commas. // Hence we split the returned string into parts char[] splitter = {','} ; string[] temp = res.Split(splitter);
// Check if the string array returned has more than one // elements since if there are less than one elements // then an exception must have been returned if(temp.Length >1) { // The WebService returns a lot of information about the // stock. We only show the relevant portions // Set the label to current Index curindex.Text = "Current Index :"+temp[1];
// Set the label to current Date Time curdate.Text ="Last Update on"+temp[2]+" at "+temp[3]; } else { error.Text = "Error :"+res ; file://set the error label } } </script>