0

I am downloading data from yahoo stocks using the Web.DownloadString(); the site will have multiply users so I need to have the client send the download request rather than the server to avoid getting blocked from sending too many request from the servers Ip address. I can't find a way to run it on the client side and am looking for assistance making it run from client rather than server.

below is a poorly formatted function that I plan to clean up that I am using right now

I plan only do use the part required to get the data run client side and the rest run server I have just yet to clean up my code.

 Public void DownloadData() 
 {
        string csvData = null;
        string month1 = Convert.ToString(DropDownList1.SelectedIndex);
        string month2 = Convert.ToString(DropDownList2.SelectedIndex);
        string Temp = "http://ichart.finance.yahoo.com/table.csv?s=" + SymbolName.Text + "&d=" + month2 + "&e=" + TextBox3.Text + "&f=" + TextBox4.Text + "&g=d&a=" + month1 + "&b=" + TextBox1.Text + "&c=" + TextBox2.Text + "&ignore=.csv";
        string FileRead;
        List<string> Remove1 = new List<string>();
        string path = System.AppDomain.CurrentDomain.BaseDirectory;
        using (WebClient web = new WebClient())
        {
            try
            {
                csvData = web.DownloadString(Temp);
            }

            catch
            {

            }
        }
        if (csvData != null && csvData != "")
        {
          File.WriteAllText(path + "\\MyTest.txt", csvData);
        }

       System.IO.StreamReader file = new System.IO.StreamReader(path + "\\MyTest.txt");
          while ((FileRead = file.ReadLine()) != null) //reads from file
        {
            Remove1.Add(FileRead);
        }
        file.Close();

        csvData = csvData.Replace("Date,Open,High,Low,Close,Volume,Adj Close", "");



        List<stock> prices = YahooFinance.Parse(csvData);
        double Lowest = 0;
        foreach (stock price in prices) // finds lowest value to addjust priceing 
        {
            if (Lowest == 0)
            {
                Lowest = Convert.ToDouble(price.low);
            }
            if (Lowest > Convert.ToDouble(price.low))
            {
                Lowest = Convert.ToDouble(price.low);
            }
        }
        //  new double[] { Convert.ToDouble(price.low), Convert.ToDouble(price.high), Convert.ToDouble(price.Open), Convert.ToDouble(price.close) }
        Chart1.ChartAreas[0].AxisX.Interval = 2;
        Chart2.ChartAreas[0].AxisX.Interval = 2;
        Chart1.ChartAreas[0].AxisX.Maximum = prices.Count + 20;
        Chart1.ChartAreas[0].AxisY.Minimum = Lowest - 3;
        foreach (stock price in prices)
        {
            Chart1.Series[0].Points.AddXY(price.date, Convert.ToDouble(price.low), Convert.ToDouble(price.high), Convert.ToDouble(price.Open), Convert.ToDouble(price.close));
            Chart2.Series[0].Points.AddXY(price.date, Convert.ToDouble(price.Volume));
        }


    }

`

  • 1
    have you tried using a jquery ajax request $.ajax(Temp)? – Warrenn enslin Jan 28 '14 at 22:53
  • 1
    Theoretically, you cant make a client do anything from the server. And then there is JavaScript. Use JS to download file from Yahoo and send the text to the server as POST data and do the manipulation there. – user2930100 Jan 28 '14 at 22:54
  • I have read there is no built in way to do it with javascript and that there are things built into browsers to prevent that kind of thing. – user2901440 Jan 30 '14 at 00:17

0 Answers0