# Export dasboard data to csv

**URL:** <https://www.epiusers.help/t/export-dasboard-data-to-csv/79526>\
**Category:** Epicor ERP 10\
**Tags:** dashboard, customization, e10, epicor\
**Created:** [June 11, 2021, 8:40am UTC](https://www.epiusers.help/t/export-dasboard-data-to-csv/79526 "2021-06-11T08:40:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Justas](https://www.epiusers.help/letter_avatar_proxy/v4/letter/j/9fc29f/32.png) [@Justas](https://www.epiusers.help/u/Justas)\
**Post date:** [June 11, 2021, 8:40am UTC](https://www.epiusers.help/t/export-dasboard-data-to-csv/79526/1 "2021-06-11T08:40:46Z")

</div>

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** :

```auto
	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());
       }
    }
}

```

**Expected output is** :

![2021-06-11 11_38_20-prwez0pl.p5e - Excel](https://www.epiusers.help/uploads/default/original/3X/8/4/84c8d84951afda6f27254170bee76d801d45834e.png)

---

<div class="post-metadata">

**Author:** ![NateS](https://www.epiusers.help/user_avatar/www.epiusers.help/nates/32/18519_2.png) [@NateS](https://www.epiusers.help/u/NateS)\
**Post date:** [June 11, 2021, 12:26pm UTC](https://www.epiusers.help/t/export-dasboard-data-to-csv/79526/2 "2021-06-11T12:26:50Z")

</div>

> [@Justas](#):
>
> for (i=0; i \< Count - 1; i++)

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.

```cs
Count = edvPP.dataView.Table.Rows.Count();

```

Having said all this, I have never exported data this way from a button click.  
Good Luck!  
Nate

---

<div class="post-metadata">

**Author:** ![timshuwy](https://www.epiusers.help/user_avatar/www.epiusers.help/timshuwy/32/90122_2.png) [@timshuwy](https://www.epiusers.help/u/timshuwy)\
**Post date:** [June 11, 2021, 4:56pm UTC](https://www.epiusers.help/t/export-dasboard-data-to-csv/79526/3 "2021-06-11T16:56:32Z")

</div>

You might be able to simply get rid of the for i loop by changing it to a foreach loop. Then you can get rid of the itterator and the count.

```auto
private void epiButtonC1_Click(object sender, System.EventArgs args) {
        // **Place Event Handling Code Here**
        EpiDataView edvPP = (EpiDataView) (oTrans.EpiDataViews[“V_JOB_EXCEPTIONS_1View”]);

        using(System.IO.StreamWriter sw = new System.IO.StreamWriter(@“ C: \Location\ Test.CSV”)) {
            foreach (DataRow dr in edvPP.dataView.Table.Rows) {
                foreach (var ay in dr.ItemArray) {
                    sw.Write(ay.ToString() + “”);
                }
            }
        }

```

---

<div class="post-metadata">

**Author:** ![kylepbsps](https://www.epiusers.help/user_avatar/www.epiusers.help/kylepbsps/32/30579_2.png) [@kylepbsps](https://www.epiusers.help/u/kylepbsps)\
**Post date:** [August 18, 2021, 8:33pm UTC](https://www.epiusers.help/t/export-dasboard-data-to-csv/79526/4 "2021-08-18T20:33:54Z")

</div>

Ill post my code once I have it sorted out.

---

<div class="post-metadata">

**Author:** ![kylepbsps](https://www.epiusers.help/user_avatar/www.epiusers.help/kylepbsps/32/30579_2.png) [@kylepbsps](https://www.epiusers.help/u/kylepbsps)\
**Post date:** [August 19, 2021, 4:41pm UTC](https://www.epiusers.help/t/export-dasboard-data-to-csv/79526/5 "2021-08-19T16:41:37Z")

</div>

Here is the code i’m using for my own purposes.

> 

```
private void EasyButton_Click(object sender, System.EventArgs args)
{
	// **Place Event Handling Code Here**
	EpiDataView edvPP = (EpiDataView)(oTrans.EpiDataViews["V_kpNameplateData_1View"]);

	using (System.IO.StreamWriter sw = new System.IO.StreamWriter(@"C:\temp\NameplateData.CSV", false, System.Text.Encoding.UTF32))

	{
		char ctab = '\t';
		string stab = "\t";
		string newline = "\n";
		string[] headerList = {"model", "serial #", "Rating"}; 
		string header = "";
		string detail = "";
		
		header = string.Join(stab, headerList);
		sw.Write(header + newline);

		foreach (DataRow dr in edvPP.dataView.Table.Rows) {
			foreach (var ay in dr.ItemArray) {
			sw.Write(ay.ToString() + "" + ctab);
			}
		}		
	}
}

```

}

 ![image](https://www.epiusers.help/uploads/default/original/3X/c/6/c65fe79519f983861d743e93fe87acfb1c835c6e.png)

---

<div class="post-metadata">

**Author:** ![Justas](https://www.epiusers.help/letter_avatar_proxy/v4/letter/j/9fc29f/32.png) [@Justas](https://www.epiusers.help/u/Justas)\
**Post date:** [August 20, 2021, 8:15am UTC](https://www.epiusers.help/t/export-dasboard-data-to-csv/79526/6 "2021-08-20T08:15:20Z")

</div>

Hi,

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?

 ![image](https://www.epiusers.help/uploads/default/original/3X/c/a/ca6c4500d2ece8ef993c2739b39847e0a180499d.png)

---

<div class="post-metadata">

**Author:** ![Justas](https://www.epiusers.help/letter_avatar_proxy/v4/letter/j/9fc29f/32.png) [@Justas](https://www.epiusers.help/u/Justas)\
**Post date:** [August 20, 2021, 10:31am UTC](https://www.epiusers.help/t/export-dasboard-data-to-csv/79526/7 "2021-08-20T10:31:31Z")

</div>

Ok figured out how to jump to new line on each row(added \n after first loop instead before), but can not get rid of sysrow  
 ![image](https://www.epiusers.help/uploads/default/original/3X/0/2/024e069aa2f1abf987980aa57f44214efbe2f89e.png)

```
	{
		char ctab = '\t';
		string stab = "\t";
		string newline = "\n";
		string[] headerList = {"Load", "Character01"}; 
		string header = "";
		string detail = "";
		
		header = string.Join(stab, headerList);
		sw.Write(header);
		foreach (DataRow dr in edvPP.dataView.Table.Rows) {
		sw.Write(newline);
			foreach (var ay in dr.ItemArray) {
			sw.Write(ay.ToString() + "" + ctab);
			}
		}		
	}
}
}
```

---

<div class="post-metadata">

**Author:** ![Justas](https://www.epiusers.help/letter_avatar_proxy/v4/letter/j/9fc29f/32.png) [@Justas](https://www.epiusers.help/u/Justas)\
**Post date:** [August 20, 2021, 11:28am UTC](https://www.epiusers.help/t/export-dasboard-data-to-csv/79526/8 "2021-08-20T11:28:43Z")

</div>

@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.  
 ![image](https://www.epiusers.help/uploads/default/original/3X/5/f/5f7fcf2c571ff3fd2700aa58f47032e686e6700b.png)

```
private void epiButtonC1_Click(object sender, System.EventArgs args)
	{
		// **Place Event Handling Code Here**
EpiDataView edvPP = (EpiDataView)(oTrans.EpiDataViews["MyView"]);

	using (System.IO.StreamWriter sw = new System.IO.StreamWriter(@"temp\NameplateData.CSV", false, System.Text.Encoding.UTF32))

	{
		char ctab = '\t';
		string stab = "\t";
		string newline = "\n";
		string[] headerList = {"Load", "Character01"}; 
		string header = "";
		string detail = "";
		
		header = string.Join(stab, headerList);
		sw.Write(header);

		foreach (DataRow dr in edvPP.dataView.ToTable().Rows) {
                sw.Write(newline);
			

			sw.Write(dr["Calculated_sum"].ToString() + "" + ctab + dr["UD02_Character01"].ToString());
			
		}		
	}
}
}
```
