我正在开发一个API,其中文件是在HttpPostedFile中接收到的一个文件,所以我想读取这些行并遍历所有行:
public IList<string> ReadTextFileAndReturnData(HttpPostedFile file)
{
IList<string> _responseList = new List<string>();
//string result = new StreamReader(file.InputStream).ReadToEnd();
// Not sure how to get all lines from Stream
foreach (var line in lines)
{
// This is what I want to do
// IList<string> values = line.Split('\t');
// string data = values[0];
// _responseList.Add(data);
}
return _responseList;
}发布于 2018-10-03 12:21:35
var lines = new List<string>();
using(StreamReader reader = new StreamReader(file.InputStream))
{
do
{
string textLine = reader.ReadLine();
lines.Add(textLine);
} while (reader.Peek() != -1);
}https://stackoverflow.com/questions/52626854
复制相似问题