0

I need download a CSV file and then read it. Here is my code:

tickerValue = "goog"
Dim strURL As String = "http://ichart.yahoo.com/table.csv?s=" & tickerValue
Dim strBuffer As String = RequestWebData(strURL)
Using streamReader = New StreamReader(strBuffer)
Using reader = New CsvReader(streamReader)

I keep getting this error: An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll Additional information: Illegal characters in path.

What am I doing wrong?

Additional Info

In another part of my program I use this code and it works fine.

Address = http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=AMEX&render=download
Dim strBuffer As String = Historical_Stock_Prices.RequestWebData(Address)
Using streamReader = New StringReader(strBuffer)
Using reader = New CsvReader(streamReader)

Isn't my second code the same concept as my problem code?

rene
  • 41,474
  • 78
  • 114
  • 152
gromit1
  • 577
  • 2
  • 14
  • 36
  • 1
    While bedug what is strBuffer value before initialize streamreader? – kostas ch. Nov 12 '13 at 15:17
  • @kostasch. strBuffer value is the CSV File data. Example: `Date,Open,High,Low,Close,Volume,Adj Close 2013-11-11,1009.51,1015.93,1008.00,1010.59,1112600,1010.59 2013-11-08,1008.75,1018.50,1008.50,1016.03,1290800,1016.03 2013-11-07,1022.61,1023.93,1007.64,1007.95,1679600,1007.95 2013-11-06,1025.60,1027.00,1015.37,1022.75,912900,1022.75 2013-11-05,1020.35,1031.65,1017.42,1021.52,1181400,1021.52 2013-11-04,1031.50,1032.37,1022.03,1026.11,1138800,1026.11 2013-11-01,1031.79,1036.00,1025.10,1027.04,1283300,1027.04 2013-10-31,1028.93,1041.52,1023.97,1030.58,1616400,1030.58` – gromit1 Nov 12 '13 at 15:46
  • @kostasch. I've added more information to my original post. Could you take a look at it and tell me what you think? – gromit1 Nov 12 '13 at 15:53
  • 1
    you are using StringReader in your second snippet which you say "works". The first code, you are using a stream reader - this is different – Ahmed ilyas Nov 12 '13 at 15:55

1 Answers1

1

you are giving it, essentially, a web url. somewhere in your code, it does not support the web url. it could be the streamreader. it could be the CsvReader. what line of code does this point to?

the best bet is to save the file TO DISK, then read from disk.

UPDATE

here is an example to SAVE to disk:

using writer as new StreamWriter("C:\Test.csv")
   writer.Write(strBuffer)
   writer.Close()
end using

here is an example to READ from disk:

using strReader as new StreamReader("C:\Test.csv")
   ' this code is presumably how it works for reading into the CsvReader:
   using reader as new CsvReader(strReader)
      ' now do your thing
   end using
   strReader.Close()
end using
Ahmed ilyas
  • 5,722
  • 8
  • 44
  • 72
  • I will have hundreds of these CSV files. One for every ticker symbol. Will it be effective for me to save everyone to disk? Or should I try a different CSV reader? – gromit1 Nov 12 '13 at 15:13
  • 1
    you could try a different CSVReader but i cannot say. :) did you try it with a few files first, to save to disk then read from disk? which line of code does the exception get thrown from? – Ahmed ilyas Nov 12 '13 at 15:14
  • It points to this line of code `Using streamReader = New StreamReader(strBuffer)` – gromit1 Nov 12 '13 at 15:14
  • No I haven't tried that yet. I've had code similar to this up and running just using the URL but I downloaded the CSVReader to make my code more efficient. I'm not sure which way to go from here. Forward or back to my original code. – gromit1 Nov 12 '13 at 15:16
  • 2
    Ah! the problem is, you are giving it a string of data to StreamReader. StreamReader needs a path to the file on disk – Ahmed ilyas Nov 12 '13 at 15:16
  • What's the best way to fix this? – gromit1 Nov 12 '13 at 15:47
  • 1
    as I said... save that file to disk using the FileWriter perhaps or streamwriter, then read the file you just saved to disk using the StreamReader :) – Ahmed ilyas Nov 12 '13 at 15:48
  • 1
    I have updated the code with an example to save to disk and read to disk. – Ahmed ilyas Nov 12 '13 at 15:52
  • Thanks! I've also added more information to my original post. Could you take a look at it and tell me what you think? – gromit1 Nov 12 '13 at 15:53
  • 1
    The difference is, you are using a STRINGREADER in your second code, and STREAMREADER on your first code - thats the problem. you need to use STRINGREADER to read the string and not STREAMREADER. – Ahmed ilyas Nov 12 '13 at 15:54