using System; using System.IO; using System.Net; using System.Text; //Compile: csc /r:System.dll /r:System.Net.dll /r:System.IO.dll /target:library C:\DataFiles\C#\SMTP\quoter2.cs public class Quoter { public Quote GetQuote(string symbol) { string[] tokens; Quote q = new Quote(); q.Symbol = symbol; try{ HttpWebRequest wr = (HttpWebRequest)WebRequestFactory.Create ("http://quote.yahoo.com/d/quotes.csv?s="+ symbol + "&f=sl1d1t1c1ohgvj1pp2owern&e=.csv"); HttpWebResponse ws = (HttpWebResponse)wr.GetResponse(); StreamReader sr = new StreamReader(ws.GetResponseStream(),Encoding.ASCII); string data = sr.ReadLine(); tokens = data.Split(new char[]{','}); q.Symbol = tokens[0].Trim(new char[]{'"'}); q.Last = tokens[1].Trim(new char[]{'"'}); q.Change = tokens[11].Trim(new char[]{'"'}); q.Name = tokens[16].Trim(new char[]{'"'}); return q; } catch(Exception e) { Console.WriteLine(e.ToString()); Console.ReadLine(); return q; } } } public class Quote { string name; string symbol; string last; string change; public override string ToString() { return name + "\r\n" + symbol + "\r\n" + last + "\r\n" + change + "\r\n"; } public string Last { get {return last;} set {last = value;} } public string Change { get {return change;} set {change = value;} } public string Symbol { get {return symbol;} set {symbol = value;} } public string Name { get {return name;} set {name = value;} } }