So I am generating reports which I then present the user a button to export the report.
When they click on the export button I run Export CSV File in server action.
Once I get a success on the server action I start the download of the file.
My problem is depending on the size of the report, the excel file is sometimes still being written to, and therefore I get one of two issues.
The first one I get some of the times. "Message": "The process cannot access the file 'C:\\wwwMe2You\\reports\\3_21-Apr-2020-1509_Report.csv' because it is being used by another process.",
Or the second is the download will start and somehow pull down the file missing a lot of data because the file had not finished being written to.
As the server action sends back a success even though the files are still been written too there is no way to prevent the download from starting.
@brad The only option I had was to add a condition based on the number of days selected for the report and add a wait where applicable.
eg.
If the number of days is < 30, Export the report with no “Wait”
If the number of days is between 30 and 180, Export the report with “Wait” 1500
If the number of days is > 180, Export the report with “Wait” 5000
I got the wait times from trial and error based on the amount of data was being returned.
It’s not the prettiest, but no other options were offered by the community.
@Teodor, no matter what I tried, the report was still being written to in windows (ie. when viewing in Explorer you could see the file size still growing) even after “Export CSV File” returned a 200 and the “Download File” which was the next step would run and therefore download a partial file.