通常我們讀檔都會使用StreamReader,但往往只能讀一次,無法從頭開始。
最基本的如下:
try
{
     using (StreamReader SR = new StreamReader(路徑)
    {
          string Line;
           while ((Line = SR.ReadLine()) != null) //一次讀一行
           {
                  string[] ReadLine_Array = Line.Split(',');//csv檔用逗號做分隔
                  //這邊可以處理文件
           }
     }
 }
 catch (IOException)
 { }
 catch (NullReferenceException)
 { }
 catch (FormatException)
 { }
在using裡面讀完一次就無法再從頭讀起,因此我們需要增加
StreamReader.ReadToEnd();//標頭拉到尾
StreamReader.BaseStream.Seek(0, SeekOrigin.Begin);//標頭重新回到最開始
增加以後就可以讓 檔案再次從頭讀起!
End