[問題] 路徑中含有不合法的字元

看板C_Sharp作者 (燦爛流星)時間17年前 (2009/03/07 11:47), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
請問為什麼透過listBox1清單取得的檔案路徑會「不合法」... string FilePath = listBox1.SelectedItem.ToString(); MessageBox.Show(FilePath);//show D:\123.txt try { StreamReader sr = new StreamReader(FilePath, Encoding.Unicode, true); } catch (ArgumentException ex) { MessageBox.Show(ex.Message);//show 路徑含有不合法的字元 } 若我不從 listBox1 清單取得,直接指派路徑給 StreamReader 就能正常讀取不會有錯誤。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 120.96.54.179 ※ 編輯: gd3727 來自: 120.96.54.179 (03/07 11:50) ※ 編輯: gd3727 來自: 120.96.54.179 (03/07 11:51)

03/07 15:29, , 1F
抱歉~已自己找到問題點並解決了。因為「.」字元的關係。
03/07 15:29, 1F
※ 編輯: gd3727 來自: 120.96.54.179 (03/07 15:44)
文章代碼(AID): #19iUvYSt (C_Sharp)