views:

32

answers:

0

hi guys,

is there an build-in field attribute in FileHelper library which will add header row in final generated CSV?

i have googled and didn't find much info on it. Currently i have this

DelimitedFileEngine _engine = new DelimitedFileEngine(T);

_engine.WriteStream(HttpContext.Current.Response.Output, dataSource, int.MaxValue);

It works, but without header.

I'm thinking of having an attribute like FieldTitleAttribute and use this as column header.

So, my question is at which point do i check the attirbute and insert header columns?

Have anyone done something similar before?

I would like to get the headers insert and use custom text different from the actual field name just by having an attribute on each member of the object.

[FieldTitleAttribute("Custom Title")] private string Name

and may be an options to tell the engine to insert the header when it's generated.

So when WriteStream or WriteString is called, header row will be inserted + with custom titles.

I have found a couple of Events for DelimitedFileEngine, but not what's best way to detect if the current record is the first row and how to insert a row before this?