从FileHelperEngine切换到FileHelperAsyncEngine后,似乎无法让FileHelpers库写入标头。我根据文档调用了GetFileHeader()。有任何想法吗?
<!-- language: c# -->
var engine = new FileHelperAsyncEngine<ClaimModel>();
using (engine.BeginWriteFile(file))
{
engine.HeaderText = engine.GetFileHeader();
foreach (ClaimModel claim in claims)
{
engine.WriteNext(Utils.CleanStrings(claim));
}
}
[FileHelpers.DelimitedRecord("|")]
public class ClaimModel : Model
{
[FieldQuoted()]
public string PolicyRef ;
答案 0 :(得分:3)
您需要在HeaderText
之前设置BeginWriteFile()
。
var engine = new FileHelperAsyncEngine<ClaimModel>();
engine.HeaderText = engine.GetFileHeader();
using (engine.BeginWriteFile(file))
{
foreach (ClaimModel claim in claims)
{
engine.WriteNext(Utils.CleanStrings(claim));
}
}