下面的代码用于在 ASP .NET MVC2 中使用 FileHelpers 读取固定宽度上传的文件内容文本文件
第一行和最后一行的长度较小,因此 ReadStream 会导致异常。所有其他线条都有适当的固定宽度。如何无一例外地跳过第一行和最后一行或其他方式读取数据?
[FixedLengthRecord()]
class Bank
{
[FieldFixedLength(4)]
public string AINETUNNUS;
[FieldFixedLength(16)]
public string TEKST1;
[FieldFixedLength(3)]
public string opliik;
[FieldFixedLength(2)]
public string hinnalis;
};
[AcceptVerbs(HttpVerbs.Post)]
[Authorize]
public ActionResult LoadStatement(HttpPostedFileBase uploadFile)
{
FileHelperEngine engine = new FileHelperEngine(typeof(Bank));
var res = engine.ReadStream(new StreamReader(uploadFile.InputStream,
Encoding.GetEncoding(1257))) as Bank[];
}