ReadToEnd();
CHAPTER 10 ?– BUILDING A SAMPLE APPLICATION USING ASP.NET AJAX 239
DataTable theTable = CsvParser.Parse(s);
if (nDays > 0)
{
int i = nDays + 1;
while (theTable.Rows.Count > i)
{
theTable.Rows.RemoveAt(i);
}
}
data.Close();
reader.Close();
return theTable;
}
This makes the connection to the Yahoo! server to fetch historical data of about 10
years by using an object derived from the WebClient class, which is defined in the
System.Net namespace. To use this, you use its OpenRead method, which is pointed at a
URI. This returns a stream, which can be read by a StreamReader. The contents of this can
be parsed into a string using a CsvParser abstract helper class.
This helper class provides the parsing functionality that reads the CSV information
and returns it as a DataTable. The Source Code/Download area of the Apress web site
(www.apress.com) includes a version of this class that was derived from one published in
the excellent blog from Andreas Knab at http://knab.ws/blog/.
The call to the Yahoo! iFinance server provides the entire price history for the stock,
which can be thousands of days??™ worth of information.
Pages:
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335