我在实际项目中的两个例子:
//读取服务端的txt文档的第一行方法
FileStream fs = new FileStream(FileFullPath,FileMode.Open,FileAccess.ReadWrite);
StreamReader m_streamReader = new StreamReader(fs);
m_streamReader.BaseStream.Seek(0,SeekOrigin.Begin);
string strLine = m_streamReader.ReadLine ( ) ;
m_streamReader.Close();
StreamReader m_streamReader = new StreamReader(fs);
m_streamReader.BaseStream.Seek(0,SeekOrigin.Begin);
string strLine = m_streamReader.ReadLine ( ) ;
m_streamReader.Close();
//读取客户端的txt文档的第一行方法
Stream FileStr = this.file1.PostedFile.InputStream;
StreamReader reader = new StreamReader(FileStr);
string strLine = reader.ReadLine().ToString();
FileStr.Close();
reader.Close();
StreamReader reader = new StreamReader(FileStr);
string strLine = reader.ReadLine().ToString();
FileStr.Close();
reader.Close();