# Export to .csv using perspective 8.0

**URL:** <https://forum.inductiveautomation.com/t/export-to-csv-using-perspective-8-0/65204>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [October 13, 2022, 7:55pm UTC](https://forum.inductiveautomation.com/t/export-to-csv-using-perspective-8-0/65204 "2022-10-13T19:55:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Levi\_Overmyer](https://avatars.discourse-cdn.com/v4/letter/l/5f9b8f/32.png) [@Levi\_Overmyer](https://forum.inductiveautomation.com/u/Levi_Overmyer)\
**Post date:** [October 13, 2022, 7:55pm UTC](https://forum.inductiveautomation.com/t/export-to-csv-using-perspective-8-0/65204/1 "2022-10-13T19:55:59Z")

</div>

I have set up a transaction group and a SQL query along with export button. This currently saves a file on the server to a folder. How do I export the whole query straight from the browser to save as .csv right to my PC? This is what i am currently using to export.

 ![Screenshot (22)](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/7/17dd0ba2241268c019478302ca60a12056d23970.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 13, 2022, 8:24pm UTC](https://forum.inductiveautomation.com/t/export-to-csv-using-perspective-8-0/65204/2 "2022-10-13T20:24:29Z")

</div>

You must use `system.perspective.download()` instead of `system.file.writeFile`.

---

<div class="post-metadata">

**Author:** ![Levi\_Overmyer](https://avatars.discourse-cdn.com/v4/letter/l/5f9b8f/32.png) [@Levi\_Overmyer](https://forum.inductiveautomation.com/u/Levi_Overmyer)\
**Post date:** [October 13, 2022, 8:45pm UTC](https://forum.inductiveautomation.com/t/export-to-csv-using-perspective-8-0/65204/3 "2022-10-13T20:45:39Z")

</div>

> [@pturmel](#):
>
> system.perspective.download()

Does not work. I tried with a name and without

 ![Screenshot (24)](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/f/bf6895c40a1cbe818b58da175e81757e703ef34e.png)  
 ![Screenshot (25)](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/d/bd86edcdcbdb2daf58a643089066829562fe23c0.png)

---

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [October 13, 2022, 8:54pm UTC](https://forum.inductiveautomation.com/t/export-to-csv-using-perspective-8-0/65204/4 "2022-10-13T20:54:44Z")

</div>

Here is what I use on one of my buttons, may point you in the right direction.

```auto
	selection = self.getSibling("Type Dropdown").custom.Selected
	table = self.parent.parent.parent.parent.getChild("Right Container").getChild("Table").props.data
	data = system.dataset.toExcel(True, [table])
	filename = "%s Asset List.xlsx" % selection
	system.perspective.download(filename,data)	

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 13, 2022, 9:12pm UTC](https://forum.inductiveautomation.com/t/export-to-csv-using-perspective-8-0/65204/5 "2022-10-13T21:12:03Z")

</div>

It is a browser download. You don't get to specify a folder, and the filename you supply is only a suggestion, not enforced. The browser will pop up a window asking the user where to save the file.

It is a browser download. You cannot control the final placement or name.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [October 13, 2022, 9:47pm UTC](https://forum.inductiveautomation.com/t/export-to-csv-using-perspective-8-0/65204/6 "2022-10-13T21:47:07Z")

</div>

Tip: Post code - not pictures of code - and use the `</>` code formatting button to preserve code indentation and apply syntax highlighting. That way it will be much more legible and we can copy and paste the code into our answers.

---

<div class="post-metadata">

**Author:** ![Levi\_Overmyer](https://avatars.discourse-cdn.com/v4/letter/l/5f9b8f/32.png) [@Levi\_Overmyer](https://forum.inductiveautomation.com/u/Levi_Overmyer)\
**Post date:** [October 13, 2022, 10:12pm UTC](https://forum.inductiveautomation.com/t/export-to-csv-using-perspective-8-0/65204/7 "2022-10-13T22:12:34Z")

</div>

That is all I need at this point. I will try again tomorrow when I’m at the plant. My time working on this is limited unfortunately.

---

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [October 14, 2022, 3:54am UTC](https://forum.inductiveautomation.com/t/export-to-csv-using-perspective-8-0/65204/8 "2022-10-14T03:54:48Z")

</div>

I had something similar I needed to do myself later on, so just went ahead and done it now. Hash out the parts you don't need and change the path and parameters for the named query. Right click on the named query in your list and select copy path, then paste that between the quotes. If you not using parameters you can delete them from the named query and select the appropriate line below.

```auto
	##Code to download a xlsx or csv file
	path = "Equipment/TestQuery"
	#If more params, comma seperate them inside the curley brackets or hash out if not using
	params = {'location':"USA"}
	ds = system.db.runNamedQuery(path, params)
    #if you are not using parameters use the below
    #ds = system.db.runNamedQuery(path, {})
	#Select CSV or Xlsx code
	data = system.dataset.toCSV(ds)
	#data = system.dataset.toExcel(True, [ds])
	#Select csv or xlsx path
	#filename = "Downloaded File.xlsx"
	filename = "Downloaded File.csv"
	system.perspective.download(filename,data)
	#Write dataset to custom property to make sure named query is returning
	self.custom.queryresult = ds

```

[https://docs.inductiveautomation.com/display/DOC80/system.db.runNamedQuery](https://docs.inductiveautomation.com/display/DOC80/system.db.runNamedQuery)
