2015-03-02 103 views
-2

我遇到了一些webclient下載問題。 我想從一個網站收集一些數據,並在我的計算中使用數據(單獨的列)。簡單地複製和粘貼數據時(並手動刪除文件底部的空行),我不會出錯。但是,當試圖自動化它 - 我得到「路徑中的非法字符」錯誤。在文件結尾處認爲它是\ r和「」 - 這就是問題所在。我試圖使用.TrimEnd,但我仍然收到錯誤。有任何想法嗎? 。Webclient下載 - 路徑中的非法字符

輸出在當地人窗口(修改後的代碼「download.Split( '\ n');) 最後的值。 「\ 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)); 
    } 
+0

你爲什麼要在你下載的字符串(而不是實際的文件名)上調用'File.ReadAllLines'? – 2015-03-02 15:59:58

回答

0

待辦事項您嘗試從Web客戶端下載路徑讀取文件

還是你嘗試分析內容HTTP響應在這種情況下,你應該使用下列內容:??

string downloadString = client.downloadString(/* ... */); 
lines = downloadString.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntities) 
+0

我試圖按照你的建議,而這實際上似乎在伎倆!非常感謝@Sharihin!和其他人試圖幫助! – user3463116 2015-03-02 16:27:55