# Export Data - Choose or create export file

**URL:** <https://forum.inductiveautomation.com/t/export-data-choose-or-create-export-file/83371>\
**Category:** Ignition\
**Created:** [December 20, 2023, 3:09pm UTC](https://forum.inductiveautomation.com/t/export-data-choose-or-create-export-file/83371 "2023-12-20T15:09:03Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![HelloWorld](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@HelloWorld](https://forum.inductiveautomation.com/u/HelloWorld)\
**Post date:** [December 20, 2023, 3:09pm UTC](https://forum.inductiveautomation.com/t/export-data-choose-or-create-export-file/83371/1 "2023-12-20T15:09:04Z")

</div>

```auto
results = system.db.runNamedQuery("Fetch Records",{})
spreadsheet = system.dataset.toExcel(True, [results])
filePath = "C:\\output\\results.xlsx"
system.file.writeFile(filePath, spreadsheet)

```

Instead of hard coding the filepath - can the client choose a file location or create a new one if they wish ???

---

<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:** [December 20, 2023, 3:16pm UTC](https://forum.inductiveautomation.com/t/export-data-choose-or-create-export-file/83371/2 "2023-12-20T15:16:25Z")

</div>

Which UI?

If Vision, there are utilities to pop up a file/folder selection.

If Perspective, you must use `system.perspective.download()`, and cannot dictate where the file ends up, and can only _suggest_ a file name.

If this will run in the gateway to save into the gateway filesystem, you will need to provide a file path through some indirect means.

---

<div class="post-metadata">

**Author:** ![HelloWorld](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@HelloWorld](https://forum.inductiveautomation.com/u/HelloWorld)\
**Post date:** [December 20, 2023, 3:30pm UTC](https://forum.inductiveautomation.com/t/export-data-choose-or-create-export-file/83371/3 "2023-12-20T15:30:10Z")

</div>

Thanks could you elaborate on how something could run in the gateway and not perspective ?

---

<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:** [December 20, 2023, 3:36pm UTC](https://forum.inductiveautomation.com/t/export-data-choose-or-create-export-file/83371/4 "2023-12-20T15:36:15Z")

</div>

I would expect the user of a Perspective UI to want a file to be placed in the machine on which the client browser is running. You cannot write from a script to a client browser's local filesystem. (Nor read anything, either.) Browsers don't allow that malware-ish behavior.

There are many reasons a script running in a gateway might want to write into a file in the gateway, but it wouldn't be expected to be accessible to any client.

---

<div class="post-metadata">

**Author:** ![HelloWorld](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@HelloWorld](https://forum.inductiveautomation.com/u/HelloWorld)\
**Post date:** [December 20, 2023, 3:42pm UTC](https://forum.inductiveautomation.com/t/export-data-choose-or-create-export-file/83371/5 "2023-12-20T15:42:00Z")

</div>

What about a file upload component - if the script is running in perspective and the client uses that component with that script.

---

<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:** [December 20, 2023, 3:46pm UTC](https://forum.inductiveautomation.com/t/export-data-choose-or-create-export-file/83371/6 "2023-12-20T15:46:55Z")

</div>

Sure, if you are uploading, you might expect to save in the gateway. If you want client control over the file name (potentially dangerous!), give them a text field for that. Giving them any option to pick an arbitrary destination _folder_ in the _gateway_ is crazy.

---

<div class="post-metadata">

**Author:** ![HelloWorld](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@HelloWorld](https://forum.inductiveautomation.com/u/HelloWorld)\
**Post date:** [December 20, 2023, 3:50pm UTC](https://forum.inductiveautomation.com/t/export-data-choose-or-create-export-file/83371/7 "2023-12-20T15:50:08Z")

</div>

So are you saying I create and store files in the gateway?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 20, 2023, 4:07pm UTC](https://forum.inductiveautomation.com/t/export-data-choose-or-create-export-file/83371/8 "2023-12-20T16:07:45Z")

</div>

It's up to you.

What are you _actually trying to do_?  
The File Upload component creates temporarily files on the gateway when files are uploaded. Their location is deliberately obscured from you - they should be treated as ephemeral unless explicitly saved somewhere by you. That can be a database table with a BLOB column, a specific directory on the filesystem, into an S3 bucket via `system.net.httpClient`, whatever - it's up to you.

---

<div class="post-metadata">

**Author:** ![HelloWorld](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@HelloWorld](https://forum.inductiveautomation.com/u/HelloWorld)\
**Post date:** [December 20, 2023, 4:17pm UTC](https://forum.inductiveautomation.com/t/export-data-choose-or-create-export-file/83371/9 "2023-12-20T16:17:36Z")

</div>

I want to export data from a chart to a workbook.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 20, 2023, 4:23pm UTC](https://forum.inductiveautomation.com/t/export-data-choose-or-create-export-file/83371/10 "2023-12-20T16:23:10Z")

</div>

If you ultimately want that export to end up on whatever user agent is actually viewing your Perspective project (web browser, mobile device, workstation session) your _only option_ is `system.perspective.download`, subject to the restrictions Phil mentioned above. This isn't something we (IA) can work around - it's a fundamental behavior of web browsers that they don't allow you to look at the local filesystem, so all you can do is give the user agent a download link and _hope_ that it will accept downloading your file with the filename you suggested.
