Hi,
I’m adding custom button to dashboard which should export data to csv file. Could use BAQ export but it exports as standard csv with quotes(which is not good). What i need is data structure to be exported as like mouse rclick. I’m not strong in coding the best I could do is I found some scripts, edited it to my needs, but it exports just the first column data and without column labels. What am I missing? Code:
private void epiButtonC1_Click(object sender, System.EventArgs args)
{
// ** Place Event Handling Code Here **
EpiDataView edvPP = (EpiDataView)(oTrans.EpiDataViews["V_JOB_EXCEPTIONS_1View"]);
int Count = 0;
int i = 0;
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(@"C:\Location\Test.CSV"))
{
foreach(DataRow dr in edvPP.dataView.Table.Rows)
{
object[] ay = dr.ItemArray;
for (i=0; i < Count - 1; i++)
{
sw.Write(ay[i].ToString() + "");
}
sw.WriteLine(ay[i].ToString());
}
}
}
I am not certain, but I think right here. Your for statement says “do this loop while i is less than count-1.” Your count starts at 0, so the loop only goes once. I am not sure about the syntax, but something like this might work to set your count before you get into that for loop.
Count = edvPP.dataView.Table.Rows.Count();
Having said all this, I have never exported data this way from a button click.
Good Luck!
Nate
This is basicaly almost a solution. Just one question, maybe you know fast answer. if view contains more than one row. How to jump to new line every time when row reaches the end, is some count needed? And how to ignore sysrow, do i need to point code to exact columns which are needed?
@kylepbsps thanks for code.
Finally solved the puzzle by combining your code with some additional scripts. Don’t know if this is the best way, but seems now I can get only needed rows splited per line and without sysrow.