Export to flat file

  • Thread starter Thread starter Kevin Humphreys
  • Start date Start date
K

Kevin Humphreys

Hi There,
I am developing an windows application using VB.NET and I need to export and
open the contents of my datagrid to a flat file. Preferably txt or wordpad.

Whats the best direction/chunk of code to do this?

Thanks,
Kevin.
 
I am developing an windows application using VB.NET and I need to
export and open the contents of my datagrid to a flat file. Preferably
txt or wordpad.

Whats the best direction/chunk of code to do this?

There is an open source library called "FileHelper" which can export to
CSV, Tab Delimited, etc.

SQL Server also supports file exporting... through DTS/SSIS.
 
Kevin,

Because you are talking about a DataGrid and not about a DataGridView, then
there is for sure a DataTable or DataSet as datasource.

The most simple is to save that as a XML file as

mydataset.WriteXML(path)

However you can as well loop through the tables and write a CSV or whatever.

Cor
 
Kevin Humphreys said:
Hi There,
I am developing an windows application using VB.NET and I need to export
and open the contents of my datagrid to a flat file. Preferably txt or
wordpad.

Whats the best direction/chunk of code to do this?


I don't know if this will put you in the ballpark. It just happens to be C#
and was in a Web solution. But it might give you a clue to get it to a file.


StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
DataGrid1.RenderControl(hw);
Response.Write(sw.ToString());
Response.End();
 
Back
Top