How to serve a .xls file from \webserver\webapps\main and download to browser

I have an excel report that saves to C:\Program Files\Inductive Automation\Ignition\webserver\webapps\main every hour.

How do I download this to the browser from a button? When I figure out how to read it. From the gateway directory. I can figure out the rest.

I can’t get it to read from the console. I’ve tried with and without file type and multiple “”

system.file.readFileAsBytes('C:\\Program Files\Inductive Automation\Ignition\webserver\webapps\main\ProductionReport.xls')
Traceback (most recent call last):
  File "<input>", line 16, in <module>
IOError: File 'C:\\Program Files\Inductive Automation\Ignition\webserver\webapps\main\ProductionReport.xls' doesn't exist or isn't a file.

You need to escape your backslahes, if you’re doing this from vision (including the console):
C:\\Program Files\\Inductive Automation\\Ignition\\webserver\\webapps\\main\\ProductionReport.xls

The pythonic way would be to use forward slashes.
C:/Program Files/Inductive Automation/Ignition/webserver/webapps/main/ProductionReport.xls

That said, this only works if you’re doing this on the same machine the gateway is running on.

If you’re already putting the file into /webserver/webapps/main, then you can just direct the user to ${gatewayAddress}/fileName.xls and the browser should automatically download the file.

2 Likes

So simple. Thank you!!

I guess once you serve it up once. It won’t overwrite the file when it tries to save again. From the schedule in the reporting module?

Because it was overwriting just fine. Now its not. :confused:

Bit of a known issue. Maybe try this?

1 Like

I made that change and saved. It didn’t help. Can I just restart perspective module. Or it takes an entire gateway restart? To see change.

Entire gateway restart.

that works thanks!