-2

I am having some problems with a webclient download. I am trying to collect some data form a website, and use the data (separate column) in my calculations. I get no error when simply copying and pasting data (and manually deleting the empty lines in the bottom of the file). But when trying to automate it - i get the "illegal characters in path" error. Think it's \r and "" at the end of the file - thats the problem. I have attempted to use .TrimEnd, but I am still getting the error. Any ideas?

Output in locals window.(after modified code to "download.Split('\n');) last values... "\r" "\r" ""

static void userInterface()
{
    string[] lines;
    //Console.Write("Enter ticker:  ");
    //string contract = Console.ReadLine();

    try
    {
        WebClient client = new WebClient();
        string downloadString = client.DownloadString
            ("http://ds01.ddfplus.com/historical/queryeod.ashx?username=XX&password=XXX&symbol=clk12&maxrecords=30&data=daily");
        downloadString = downloadString.TrimEnd('\r');
        //lines = File.ReadAllLines(downloadString);
        lines = downloadString.Split('\n');
        int high = 1;
        Program.TA(DateColumn(lines, high), OpenColumn(lines, high + 1), HighColumn(lines, high + 2),
            LowColumn(lines, high + 3), CloseColumn(lines, high + 4));
    }
Marc
  • 3,905
  • 4
  • 21
  • 37
user3463116
  • 1
  • 1
  • 6

1 Answers1

0

Do you try to read file from path downloaded with WebClient?

Or do you try to parse contents of http response? In this case you should use following:

string downloadString = client.downloadString(/* ... */);
lines = downloadString.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntities)
Sharihin
  • 140
  • 11
  • i tried to follow your suggestion, and this actually seems to do the trick! Thanks a lot @Sharihin! and to everyone else to tried to help! – user3463116 Mar 02 '15 at 16:27